Strong modeify the examples

This makes skyanalyzer also check the examples, and fixes everything it
found there.
This commit is contained in:
Hixie
2015-10-22 13:29:12 -07:00
parent 1dbf9bc891
commit a6c473ea95
77 changed files with 598 additions and 564 deletions

View File

@@ -48,13 +48,19 @@ class CardCollectionState extends State<CardCollection> {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
_cardModels = new List.generate(cardHeights.length, (i) => new CardModel(i, cardHeights[i]));
_cardModels = new List<CardModel>.generate(
cardHeights.length,
(int i) => new CardModel(i, cardHeights[i])
);
}
void _initFixedSizedCardModels() {
const int cardCount = 27;
const double cardHeight = 100.0;
_cardModels = new List.generate(cardCount, (i) => new CardModel(i, cardHeight));
_cardModels = new List<CardModel>.generate(
cardCount,
(int i) => new CardModel(i, cardHeight)
);
}
void _initCardModels() {
@@ -72,7 +78,7 @@ class CardCollectionState extends State<CardCollection> {
double _variableSizeToSnapOffset(double scrollOffset) {
double cumulativeHeight = 0.0;
double margins = 8.0;
List<double> cumulativeHeights = _cardModels.map((card) {
List<double> cumulativeHeights = _cardModels.map((CardModel card) {
cumulativeHeight += card.height + margins;
return cumulativeHeight;
})
@@ -112,7 +118,7 @@ class CardCollectionState extends State<CardCollection> {
context: context,
child: new IconTheme(
data: const IconThemeData(color: IconThemeColor.black),
child: new Block([
child: new Block(<Widget>[
new DrawerHeader(child: new Text('Options')),
buildDrawerCheckbox("Snap fling scrolls to center", _snapToCenter, _toggleSnapToCenter),
buildDrawerCheckbox("Fixed size cards", _fixedSizeCards, _toggleFixedSizeCards),
@@ -168,10 +174,10 @@ class CardCollectionState extends State<CardCollection> {
Navigator.of(context).pop();
}
Widget buildDrawerCheckbox(String label, bool value, Function callback) {
Widget buildDrawerCheckbox(String label, bool value, void callback()) {
return new DrawerItem(
onPressed: callback,
child: new Row([
child: new Row(<Widget>[
new Flexible(child: new Text(label)),
new Checkbox(value: value, onChanged: (_) { callback(); })
])
@@ -182,7 +188,7 @@ class CardCollectionState extends State<CardCollection> {
return new DrawerItem(
icon: icon,
onPressed: () { onChanged(itemValue); },
child: new Row([
child: new Row(<Widget>[
new Flexible(child: new Text(label)),
new Radio(
value: itemValue,
@@ -197,7 +203,7 @@ class CardCollectionState extends State<CardCollection> {
return new ToolBar(
left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer),
center: new Text('Swipe Away'),
right: [
right: <Widget>[
new Text(_dismissDirectionText(_dismissDirection))
]
);
@@ -210,7 +216,7 @@ class CardCollectionState extends State<CardCollection> {
CardModel cardModel = _cardModels[index];
Widget card = new Dismissable(
direction: _dismissDirection,
onResized: () { _invalidator([index]); },
onResized: () { _invalidator(<int>[index]); },
onDismissed: () { dismissCard(cardModel); },
child: new Card(
color: Theme.of(context).primarySwatch[cardModel.color],
@@ -272,7 +278,7 @@ class CardCollectionState extends State<CardCollection> {
child: new Container(
height: cardModel.height,
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primaryColor),
child: new Row([
child: new Row(<Widget>[
leftArrowIcon,
new Flexible(child: new Text(backgroundMessage, style: backgroundTextStyle)),
rightArrowIcon
@@ -285,7 +291,7 @@ class CardCollectionState extends State<CardCollection> {
return new IconTheme(
key: cardModel.key,
data: const IconThemeData(color: IconThemeColor.white),
child: new Stack([background, card])
child: new Stack(<Widget>[background, card])
);
}
@@ -299,8 +305,8 @@ class CardCollectionState extends State<CardCollection> {
return new LinearGradient(
begin: Point.origin,
end: new Point(0.0, bounds.height),
colors: [const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: [0.1, 0.35]
colors: <Color>[const Color(0x00FFFFFF), const Color(0xFFFFFFFF)],
stops: <double>[0.1, 0.35]
)
.createShader();
}
@@ -327,8 +333,8 @@ class CardCollectionState extends State<CardCollection> {
}
if (_sunshine)
cardCollection = new Stack([
new Column([new NetworkImage(src: _sunshineURL)]),
cardCollection = new Stack(<Widget>[
new Column(<Widget>[new NetworkImage(src: _sunshineURL)]),
new ShaderMask(child: cardCollection, shaderCallback: _createShader)
]);
@@ -351,7 +357,7 @@ class CardCollectionState extends State<CardCollection> {
)
)
);
body = new Stack([body, indicator]);
body = new Stack(<Widget>[body, indicator]);
}
return new Theme(
@@ -369,7 +375,7 @@ class CardCollectionState extends State<CardCollection> {
void main() {
runApp(new MaterialApp(
title: 'Cards',
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new CardCollection(),
}
));

View File

@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
class ContainerApp extends StatelessComponent {
Widget build(BuildContext context) {
return new Column([
return new Column(<Widget>[
new Container(
padding: new EdgeDims.all(10.0),
margin: new EdgeDims.all(10.0),
@@ -20,7 +20,7 @@ class ContainerApp extends StatelessComponent {
new Container(
decoration: new BoxDecoration(backgroundColor: const Color(0xFFFFFF00)),
padding: new EdgeDims.symmetric(horizontal: 50.0, vertical: 75.0),
child: new Row([
child: new Row(<Widget>[
new RaisedButton(
child: new Text('PRESS ME'),
onPressed: () => print("Hello World")

View File

@@ -31,11 +31,11 @@ class DatePickerDemoState extends State<DatePickerDemo> {
brightness: ThemeBrightness.light,
primarySwatch: Colors.teal
),
child: new Stack([
child: new Stack(<Widget>[
new Scaffold(
toolBar: new ToolBar(center: new Text("Date Picker")),
body: new Row(
[new Text(_dateTime.toString())],
<Widget>[new Text(_dateTime.toString())],
alignItems: FlexAlignItems.end,
justifyContent: FlexJustifyContent.center
)
@@ -48,7 +48,7 @@ class DatePickerDemoState extends State<DatePickerDemo> {
onChanged: _handleDateChanged
),
contentPadding: EdgeDims.zero,
actions: [
actions: <Widget>[
new FlatButton(
child: new Text('CANCEL')
),

View File

@@ -105,8 +105,8 @@ class DragAndDropAppState extends State<DragAndDropApp> {
),
body: new DefaultTextStyle(
style: Theme.of(context).text.body1.copyWith(textAlign: TextAlign.center),
child: new Column([
new Flexible(child: new Row([
child: new Column(<Widget>[
new Flexible(child: new Row(<Widget>[
new ExampleDragSource(navigator: config.navigator, name: 'Orange', color: const Color(0xFFFF9000)),
new ExampleDragSource(navigator: config.navigator, name: 'Teal', color: const Color(0xFF00FFFF)),
new ExampleDragSource(navigator: config.navigator, name: 'Yellow', color: const Color(0xFFFFF000)),
@@ -114,7 +114,7 @@ class DragAndDropAppState extends State<DragAndDropApp> {
alignItems: FlexAlignItems.center,
justifyContent: FlexJustifyContent.spaceAround
)),
new Flexible(child: new Row([
new Flexible(child: new Row(<Widget>[
new Flexible(child: new ExampleDragTarget()),
new Flexible(child: new ExampleDragTarget()),
new Flexible(child: new ExampleDragTarget()),
@@ -129,7 +129,7 @@ class DragAndDropAppState extends State<DragAndDropApp> {
void main() {
runApp(new MaterialApp(
title: 'Drag and Drop Flutter Demo',
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new DragAndDropApp(navigator: args.navigator)
}
));

View File

@@ -13,7 +13,7 @@ class DropdownDemo extends StatefulComponent {
class DropdownDemoState extends State<DropdownDemo> {
String _value = "Free";
List <DropdownMenuItem> _buildItems() {
List<DropdownMenuItem> _buildItems() {
return ["One", "Two", "Free", "Four"].map((String value) {
return new DropdownMenuItem<String>(value: value, child: new Text(value));
})
@@ -24,7 +24,7 @@ class DropdownDemoState extends State<DropdownDemo> {
Widget dropdown = new DropdownButton<String>(
items: _buildItems(),
value: _value,
onChanged: (dynamic newValue) {
onChanged: (String newValue) {
setState(() {
if (newValue != null)
_value = newValue;
@@ -50,7 +50,7 @@ void main() {
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new DropdownDemo(),
}
));

View File

@@ -23,7 +23,7 @@ class Circle extends StatelessComponent {
class HorizontalScrollingApp extends StatelessComponent {
Widget build(BuildContext context) {
List<Widget> circles = [
List<Widget> circles = <Widget>[
new Circle(margin: new EdgeDims.only(left: 10.0)),
new Circle(),
new Circle(),

View File

@@ -19,10 +19,10 @@ class IndexedStackDemoState extends State<IndexedStackDemo> {
});
}
List <PopupMenuItem> _buildMenu() {
List<PopupMenuItem> _buildMenu() {
TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold);
String pad = '';
return new List.generate(_itemCount, (int i) {
return new List<PopupMenuItem>.generate(_itemCount, (int i) {
pad += '-';
return new PopupMenuItem(value: i, child: new Text('$pad Hello World $i $pad', style: style));
});
@@ -30,7 +30,7 @@ class IndexedStackDemoState extends State<IndexedStackDemo> {
Widget build(BuildContext context) {
List <PopupMenuItem> items = _buildMenu();
IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5);
IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, alignment: const FractionalOffset(0.5, 0.0));
return new Scaffold(
toolBar: new ToolBar(center: new Text('IndexedStackDemo Demo')),
@@ -56,7 +56,7 @@ void main() {
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new IndexedStackDemo(),
}
));

View File

@@ -8,7 +8,7 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/': (RouteArguments args) => new Container(
padding: const EdgeDims.all(30.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new Column([
child: new Column(<Widget>[
new Text("You are at home"),
new RaisedButton(
child: new Text('GO SHOPPING'),
@@ -24,7 +24,7 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/shopping': (RouteArguments args) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFBF5FFF)),
child: new Column([
child: new Column(<Widget>[
new Text("Village Shop"),
new RaisedButton(
child: new Text('RETURN HOME'),
@@ -40,7 +40,7 @@ final Map<String, RouteBuilder> routes = <String, RouteBuilder>{
'/adventure': (RouteArguments args) => new Container(
padding: const EdgeDims.all(20.0),
decoration: new BoxDecoration(backgroundColor: const Color(0xFFDC143C)),
child: new Column([
child: new Column(<Widget>[
new Text("Monster's Lair"),
new RaisedButton(
child: new Text('RUN!!!'),

View File

@@ -86,7 +86,7 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
cardModels = new List.generate(cardHeights.length, (i) {
cardModels = new List<CardModel>.generate(cardHeights.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
@@ -121,7 +121,7 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
CardModel cardModel = cardModels[index];
return new Listener(
key: cardModel.key,
onPointerDown: (e) { return handlePointerDown(cardModel.targetKey, e); },
onPointerDown: (PointerInputEvent e) { return handlePointerDown(cardModel.targetKey, e); },
child: new Card(
key: cardModel.targetKey,
color: cardModel.color,
@@ -162,7 +162,7 @@ void main() {
accentColor: Colors.redAccent[200]
),
title: 'Cards',
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new OverlayGeometryApp()
}
));

View File

@@ -27,7 +27,7 @@ class PageableListAppState extends State<PageableListApp> {
.map((args) => new Size(args[0], args[1]))
.toList();
cardModels = new List.generate(cardSizes.length, (i) {
cardModels = new List<CardModel>.generate(cardSizes.length, (int i) {
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardSizes.length);
return new CardModel(i, cardSizes[i], color);
});
@@ -86,7 +86,7 @@ class PageableListAppState extends State<PageableListApp> {
void _showDrawer() {
showDrawer(
context: context,
child: new Block([
child: new Block(<Widget>[
new DrawerHeader(child: new Text('Options')),
new DrawerItem(
icon: 'navigation/more_horiz',
@@ -102,7 +102,7 @@ class PageableListAppState extends State<PageableListApp> {
),
new DrawerItem(
onPressed: toggleItemsWrap,
child: new Row([
child: new Row(<Widget>[
new Flexible(child: new Text('Scrolling wraps around')),
new Checkbox(value: itemsWrap)
])
@@ -115,7 +115,7 @@ class PageableListAppState extends State<PageableListApp> {
return new ToolBar(
left: new IconButton(icon: "navigation/menu", onPressed: _showDrawer),
center: new Text('PageableList'),
right: [
right: <Widget>[
new Text(scrollDirection == ScrollDirection.horizontal ? "horizontal" : "vertical")
]
);
@@ -156,7 +156,7 @@ void main() {
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new PageableListApp(),
}
));

View File

@@ -18,11 +18,12 @@ const String frogs = "http://soundbible.com/grab.php?id=2033&type=wav";
const String rattle = "http://soundbible.com/grab.php?id=2037&type=wav";
const String iLoveYou = "http://soundbible.com/grab.php?id=2045&type=wav";
class Key {
Key(this.color, this.soundUrl);
class PianoKey {
PianoKey(this.color, this.soundUrl);
final Color color;
final String soundUrl;
final MediaPlayerProxy player = new MediaPlayerProxy.unbound();
bool get isPlayerOpen => player.impl.isOpen;
@@ -51,13 +52,13 @@ class Key {
}
class PianoApp extends StatelessComponent {
final List<Key> keys = [
new Key(Colors.red[500], chimes),
new Key(Colors.orange[500], chainsaw),
new Key(Colors.yellow[500], stag),
new Key(Colors.green[500], frogs),
new Key(Colors.blue[500], rattle),
new Key(Colors.purple[500], iLoveYou),
final List<PianoKey> keys = <PianoKey>[
new PianoKey(Colors.red[500], chimes),
new PianoKey(Colors.orange[500], chainsaw),
new PianoKey(Colors.yellow[500], stag),
new PianoKey(Colors.green[500], frogs),
new PianoKey(Colors.blue[500], rattle),
new PianoKey(Colors.purple[500], iLoveYou),
];
Future connect() {
@@ -68,10 +69,9 @@ class PianoApp extends StatelessComponent {
MediaServiceProxy mediaService = new MediaServiceProxy.unbound();
try {
shell.requestService(null, mediaService);
List<Future> pending = [];
for (Key key in keys) {
List<Future<MediaPlayerPrepareResponseParams>> pending = <Future<MediaPlayerPrepareResponseParams>>[];
for (PianoKey key in keys)
pending.add(key.load(mediaService));
}
await Future.wait(pending);
} finally {
mediaService.close();
@@ -79,8 +79,8 @@ class PianoApp extends StatelessComponent {
}
Widget build(BuildContext context) {
List<Widget> children = [];
for (Key key in keys) {
List<Widget> children = <Widget>[];
for (PianoKey key in keys) {
children.add(new Flexible(
child: new Listener(
child: new Container(
@@ -99,7 +99,7 @@ Widget statusBox(Widget child) {
const darkGray = const Color(0xff222222);
return new Center(
child: new Container(
decoration: const BoxDecoration(boxShadow: const [
decoration: const BoxDecoration(boxShadow: const <BoxShadow>[
const BoxShadow(
color: mediumGray, offset: const Offset(6.0, 6.0), blur: 5.0)
], backgroundColor: darkGray),

View File

@@ -71,7 +71,7 @@ class ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
];
return new Column(
indicators
.map((c) => new Container(child: c, margin: const EdgeDims.symmetric(vertical: 15.0, horizontal: 20.0)))
.map((Widget c) => new Container(child: c, margin: const EdgeDims.symmetric(vertical: 15.0, horizontal: 20.0)))
.toList(),
justifyContent: FlexJustifyContent.center
);
@@ -83,7 +83,7 @@ class ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
child: new Container(
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
child: new BuilderTransition(
variables: [valueAnimation.variable],
variables: <AnimatedValue<double>>[valueAnimation.variable],
performance: valueAnimation.view,
builder: buildIndicators
)

View File

@@ -47,7 +47,7 @@ class ScaleAppState extends State<ScaleApp> {
double radius = size.width / 2.0 * _zoom;
Gradient gradient = new RadialGradient(
center: center, radius: radius,
colors: [Colors.blue[200], Colors.blue[800]]
colors: <Color>[Colors.blue[200], Colors.blue[800]]
);
Paint paint = new Paint()
..shader = gradient.createShader();

View File

@@ -60,7 +60,7 @@ void main() {
primarySwatch: Colors.blue,
accentColor: Colors.redAccent[200]
),
routes: {
routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new ScrollbarApp(),
}
));

View File

@@ -6,7 +6,7 @@ import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
final List<Map<int, Color>> _kColors = [
final List<Map<int, Color>> _kColors = <Map<int, Color>>[
Colors.amber,
Colors.yellow,
Colors.blue,
@@ -42,7 +42,7 @@ class CardTransition extends StatelessComponent {
return new BuilderTransition(
performance: performance,
variables: [x, opacity, scale],
variables: <AnimatedValue<double>>[x, opacity, scale],
builder: (BuildContext context) {
Matrix4 transform = new Matrix4.identity()
..translate(x.value)

View File

@@ -5,6 +5,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
typedef Widget TextTransformer(String name, String text);
class StyledTextApp extends StatefulComponent {
StyledTextAppState createState() => new StyledTextAppState();
}
@@ -19,7 +21,7 @@ class StyledTextAppState extends State<StyledTextApp> {
.toList();
}
Function toText;
TextTransformer toText;
// From https://en.wikiquote.org/wiki/2001:_A_Space_Odyssey_(film)
final String dialogText = '''
@@ -74,10 +76,10 @@ HAL: This mission is too important for me to allow you to jeopardize it.''';
Widget build(BuildContext context) {
List<Widget> lines = nameLines
.map((nameAndText) => Function.apply(toText, nameAndText))
.map((List<String> nameAndText) => Function.apply(toText, nameAndText))
.toList();
List<Widget> children = [];
List<Widget> children = <Widget>[];
for (Widget line in lines) {
children.add(line);
if (line != lines.last) {

View File

@@ -19,7 +19,7 @@ class TabbedNavigatorAppState extends State<TabbedNavigatorApp> {
views: views,
selectedIndex: selectedIndices[n],
isScrollable: isScrollable,
onChanged: (tabIndex) {
onChanged: (int tabIndex) {
setState(() { selectedIndices[n] = tabIndex; } );
}
);
@@ -46,7 +46,7 @@ class TabbedNavigatorAppState extends State<TabbedNavigatorApp> {
Iterable<TabNavigatorView> views = ["event", "home", "android", "alarm", "face", "language"]
.map((icon_name) {
return new TabNavigatorView(
label: new TabLabel(icon: "action/${icon_name}"),
label: new TabLabel(icon: "action/$icon_name"),
builder: (BuildContext context) => _buildContent(icon_name)
);
});