Rename State.config to widget everywhere (#9273)

Rename State.config to State.widget
Rename State.didUpdateConfig to State.didUpdateWidget
Renamed all State subclasses' local variables named config to something else
This commit is contained in:
xster
2017-04-10 18:32:24 -07:00
committed by GitHub
parent a5593b1678
commit 89a7fdfc56
111 changed files with 1154 additions and 1140 deletions

View File

@@ -53,31 +53,31 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
new ComponentDemoTabData(
tabName: 'RAISED',
description: _raisedText,
widget: buildRaisedButton(),
demoWidget: buildRaisedButton(),
exampleCodeTag: _raisedCode,
),
new ComponentDemoTabData(
tabName: 'FLAT',
description: _flatText,
widget: buildFlatButton(),
demoWidget: buildFlatButton(),
exampleCodeTag: _flatCode,
),
new ComponentDemoTabData(
tabName: 'DROPDOWN',
description: _dropdownText,
widget: buildDropdownButton(),
demoWidget: buildDropdownButton(),
exampleCodeTag: _dropdownCode,
),
new ComponentDemoTabData(
tabName: 'ICON',
description: _iconText,
widget: buildIconButton(),
demoWidget: buildIconButton(),
exampleCodeTag: _iconCode,
),
new ComponentDemoTabData(
tabName: 'ACTION',
description: _actionText,
widget: buildActionButton(),
demoWidget: buildActionButton(),
exampleCodeTag: _actionCode,
),
];

View File

@@ -42,10 +42,10 @@ class _ChipDemoState extends State<ChipDemo> {
return new Scaffold(
appBar: new AppBar(title: const Text('Chips')),
body: new ListView(
children: chips.map((Widget widget) {
children: chips.map((Widget chip) {
return new Container(
height: 100.0,
child: new Center(child: widget)
child: new Center(child: chip)
);
}).toList()
)

View File

@@ -130,7 +130,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
transform: new Matrix4.identity()
..translate(_offset.dx, _offset.dy)
..scale(_scale),
child: new Image.asset(config.photo.assetName, fit: BoxFit.cover),
child: new Image.asset(widget.photo.assetName, fit: BoxFit.cover),
),
),
);

View File

@@ -39,19 +39,19 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
new ComponentDemoTabData(
tabName: "CHECKBOX",
description: _checkboxText,
widget: buildCheckbox(),
demoWidget: buildCheckbox(),
exampleCodeTag: _checkboxCode
),
new ComponentDemoTabData(
tabName: "RADIO",
description: _radioText,
widget: buildRadio(),
demoWidget: buildRadio(),
exampleCodeTag: _radioCode
),
new ComponentDemoTabData(
tabName: "SWITCH",
description: _switchText,
widget: buildSwitch(),
demoWidget: buildSwitch(),
exampleCodeTag: _switchCode
)
];

View File

@@ -147,13 +147,13 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
),
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
final Recipe recipe = config.recipes[index];
final Recipe recipe = widget.recipes[index];
return new RecipeCard(
recipe: recipe,
onTap: () { showRecipePage(context, recipe); },
);
},
childCount: config.recipes.length,
childCount: widget.recipes.length,
),
),
);
@@ -209,7 +209,7 @@ class _PestoLogoState extends State<PestoLogo> {
@override
Widget build(BuildContext context) {
return new Transform(
transform: new Matrix4.identity()..scale(config.height / kLogoHeight),
transform: new Matrix4.identity()..scale(widget.height / kLogoHeight),
alignment: FractionalOffset.topCenter,
child: new SizedBox(
width: kLogoWidth,
@@ -217,13 +217,13 @@ class _PestoLogoState extends State<PestoLogo> {
overflow: Overflow.visible,
children: <Widget>[
new Positioned.fromRect(
rect: _imageRectTween.lerp(config.t),
rect: _imageRectTween.lerp(widget.t),
child: new Image.asset(_kSmallLogoImage, fit: BoxFit.contain),
),
new Positioned.fromRect(
rect: _textRectTween.lerp(config.t),
rect: _textRectTween.lerp(widget.t),
child: new Opacity(
opacity: _textOpacity.transform(config.t),
opacity: _textOpacity.transform(widget.t),
child: new Text('PESTO', style: titleStyle, textAlign: TextAlign.center),
),
),
@@ -311,7 +311,7 @@ class _RecipePageState extends State<RecipePage> {
final double appBarHeight = _getAppBarHeight(context);
final Size screenSize = MediaQuery.of(context).size;
final bool fullWidth = (screenSize.width < _kRecipePageMaxWidth);
final bool isFavorite = _favoriteRecipes.contains(config.recipe);
final bool isFavorite = _favoriteRecipes.contains(widget.recipe);
return new Scaffold(
key: _scaffoldKey,
body: new Stack(
@@ -322,9 +322,9 @@ class _RecipePageState extends State<RecipePage> {
right: 0.0,
height: appBarHeight + _kFabHalfSize,
child: new Hero(
tag: config.recipe.imagePath,
tag: widget.recipe.imagePath,
child: new Image.asset(
config.recipe.imagePath,
widget.recipe.imagePath,
fit: fullWidth ? BoxFit.fitWidth : BoxFit.cover,
),
),
@@ -363,7 +363,7 @@ class _RecipePageState extends State<RecipePage> {
new Container(
padding: const EdgeInsets.only(top: _kFabHalfSize),
width: fullWidth ? null : _kRecipePageMaxWidth,
child: new RecipeSheet(recipe: config.recipe),
child: new RecipeSheet(recipe: widget.recipe),
),
new Positioned(
right: 16.0,
@@ -398,10 +398,10 @@ class _RecipePageState extends State<RecipePage> {
void _toggleFavorite() {
setState(() {
if (_favoriteRecipes.contains(config.recipe))
_favoriteRecipes.remove(config.recipe);
if (_favoriteRecipes.contains(widget.recipe))
_favoriteRecipes.remove(widget.recipe);
else
_favoriteRecipes.add(config.recipe);
_favoriteRecipes.add(widget.recipe);
});
}
}

View File

@@ -236,7 +236,7 @@ class _OrderPageState extends State<OrderPage> {
@override
void initState() {
super.initState();
scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Shrine Order ${config.order}');
scaffoldKey = new GlobalKey<ScaffoldState>(debugLabel: 'Shrine Order ${widget.order}');
}
Order get currentOrder => ShrineOrderRoute.of(context).order;
@@ -249,7 +249,7 @@ class _OrderPageState extends State<OrderPage> {
final Order newOrder = currentOrder.copyWith(quantity: quantity, inCart: inCart);
if (currentOrder != newOrder) {
setState(() {
config.shoppingCart[newOrder.product] = newOrder;
widget.shoppingCart[newOrder.product] = newOrder;
currentOrder = newOrder;
});
}
@@ -263,8 +263,8 @@ class _OrderPageState extends State<OrderPage> {
Widget build(BuildContext context) {
return new ShrinePage(
scaffoldKey: scaffoldKey,
products: config.products,
shoppingCart: config.shoppingCart,
products: widget.products,
shoppingCart: widget.shoppingCart,
floatingActionButton: new FloatingActionButton(
onPressed: () {
updateOrder(inCart: true);
@@ -284,7 +284,7 @@ class _OrderPageState extends State<OrderPage> {
slivers: <Widget>[
new SliverToBoxAdapter(
child: new _Heading(
product: config.order.product,
product: widget.order.product,
quantity: currentOrder.quantity,
quantityChanged: (int value) { updateOrder(quantity: value); },
),
@@ -298,8 +298,8 @@ class _OrderPageState extends State<OrderPage> {
crossAxisSpacing: 8.0,
),
delegate: new SliverChildListDelegate(
config.products
.where((Product product) => product != config.order.product)
widget.products
.where((Product product) => product != widget.order.product)
.map((Product product) {
return new Card(
elevation: 1,

View File

@@ -53,7 +53,7 @@ class ShrinePageState extends State<ShrinePage> {
void _showShoppingCart() {
showModalBottomSheet<Null>(context: context, builder: (BuildContext context) {
if (config.shoppingCart.isEmpty) {
if (widget.shoppingCart.isEmpty) {
return const Padding(
padding: const EdgeInsets.all(24.0),
child: const Text('The shopping cart is empty')
@@ -61,7 +61,7 @@ class ShrinePageState extends State<ShrinePage> {
}
return new ListView(
padding: kMaterialListPadding,
children: config.shoppingCart.values.map((Order order) {
children: widget.shoppingCart.values.map((Order order) {
return new ListTile(
title: new Text(order.product.name),
leading: new Text('${order.quantity}'),
@@ -73,23 +73,23 @@ class ShrinePageState extends State<ShrinePage> {
}
void _sortByPrice() {
config.products.sort((Product a, Product b) => a.price.compareTo(b.price));
widget.products.sort((Product a, Product b) => a.price.compareTo(b.price));
}
void _sortByProduct() {
config.products.sort((Product a, Product b) => a.name.compareTo(b.name));
widget.products.sort((Product a, Product b) => a.name.compareTo(b.name));
}
void _emptyCart() {
config.shoppingCart.clear();
config.scaffoldKey.currentState.showSnackBar(new SnackBar(content: const Text('Shopping cart is empty')));
widget.shoppingCart.clear();
widget.scaffoldKey.currentState.showSnackBar(new SnackBar(content: const Text('Shopping cart is empty')));
}
@override
Widget build(BuildContext context) {
final ShrineTheme theme = ShrineTheme.of(context);
return new Scaffold(
key: config.scaffoldKey,
key: widget.scaffoldKey,
appBar: new AppBar(
elevation: _appBarElevation,
backgroundColor: theme.appBarBackgroundColor,
@@ -142,10 +142,10 @@ class ShrinePageState extends State<ShrinePage> {
)
]
),
floatingActionButton: config.floatingActionButton,
floatingActionButton: widget.floatingActionButton,
body: new NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: config.body
child: widget.body
)
);
}

View File

@@ -84,13 +84,13 @@ class GalleryAppState extends State<GalleryApp> {
});
},
showPerformanceOverlay: _showPerformanceOverlay,
onShowPerformanceOverlayChanged: config.enablePerformanceOverlay ? (bool value) {
onShowPerformanceOverlayChanged: widget.enablePerformanceOverlay ? (bool value) {
setState(() {
_showPerformanceOverlay = value;
});
} : null,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages,
onCheckerboardRasterCacheImagesChanged: config.checkerboardRasterCacheImages ? (bool value) {
onCheckerboardRasterCacheImagesChanged: widget.checkerboardRasterCacheImages ? (bool value) {
setState(() {
_checkerboardRasterCacheImages = value;
});
@@ -118,12 +118,12 @@ class GalleryAppState extends State<GalleryApp> {
}
});
},
onSendFeedback: config.onSendFeedback,
onSendFeedback: widget.onSendFeedback,
);
if (config.updateUrlFetcher != null) {
if (widget.updateUrlFetcher != null) {
home = new Updater(
updateUrlFetcher: config.updateUrlFetcher,
updateUrlFetcher: widget.updateUrlFetcher,
child: home,
);
}

View File

@@ -9,13 +9,13 @@ import 'syntax_highlighter.dart';
class ComponentDemoTabData {
ComponentDemoTabData({
this.widget,
this.demoWidget,
this.exampleCodeTag,
this.description,
this.tabName
});
final Widget widget;
final Widget demoWidget;
final String exampleCodeTag;
final String description;
final String tabName;
@@ -85,7 +85,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
style: Theme.of(context).textTheme.subhead
)
),
new Expanded(child: demo.widget)
new Expanded(child: demo.demoWidget)
],
);
}).toList(),
@@ -110,7 +110,7 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
@override
void didChangeDependencies() {
getExampleCode(config.exampleCodeTag, DefaultAssetBundle.of(context)).then<Null>((String code) {
getExampleCode(widget.exampleCodeTag, DefaultAssetBundle.of(context)).then<Null>((String code) {
if (mounted) {
setState(() {
_exampleCode = code;

View File

@@ -45,7 +45,7 @@ class _GalleryDrawerHeaderState extends State<GalleryDrawerHeader> {
: FlutterLogoStyle.markOnly,
lightColor: _logoColor.shade400,
darkColor: _logoColor.shade900,
textColor: config.light ? const Color(0xFF616161) : const Color(0xFF9E9E9E),
textColor: widget.light ? const Color(0xFF616161) : const Color(0xFF9E9E9E),
),
duration: const Duration(milliseconds: 750),
child: new GestureDetector(

View File

@@ -153,16 +153,16 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
Widget home = new Scaffold(
key: _scaffoldKey,
drawer: new GalleryDrawer(
useLightTheme: config.useLightTheme,
onThemeChanged: config.onThemeChanged,
timeDilation: config.timeDilation,
onTimeDilationChanged: config.onTimeDilationChanged,
showPerformanceOverlay: config.showPerformanceOverlay,
onShowPerformanceOverlayChanged: config.onShowPerformanceOverlayChanged,
checkerboardRasterCacheImages: config.checkerboardRasterCacheImages,
onCheckerboardRasterCacheImagesChanged: config.onCheckerboardRasterCacheImagesChanged,
onPlatformChanged: config.onPlatformChanged,
onSendFeedback: config.onSendFeedback,
useLightTheme: widget.useLightTheme,
onThemeChanged: widget.onThemeChanged,
timeDilation: widget.timeDilation,
onTimeDilationChanged: widget.onTimeDilationChanged,
showPerformanceOverlay: widget.showPerformanceOverlay,
onShowPerformanceOverlayChanged: widget.onShowPerformanceOverlayChanged,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
onCheckerboardRasterCacheImagesChanged: widget.onCheckerboardRasterCacheImagesChanged,
onPlatformChanged: widget.onPlatformChanged,
onSendFeedback: widget.onSendFeedback,
),
body: new CustomScrollView(
slivers: <Widget>[

View File

@@ -38,7 +38,7 @@ class UpdaterState extends State<Updater> {
}
_lastUpdateCheck = new DateTime.now();
final String updateUrl = await config.updateUrlFetcher();
final String updateUrl = await widget.updateUrlFetcher();
if (updateUrl != null) {
final bool wantsUpdate = await showDialog(context: context, child: _buildDialog());
if (wantsUpdate != null && wantsUpdate)
@@ -68,5 +68,5 @@ class UpdaterState extends State<Updater> {
}
@override
Widget build(BuildContext context) => config.child;
Widget build(BuildContext context) => widget.child;
}

View File

@@ -87,8 +87,8 @@ class StockHomeState extends State<StockHome> {
}
void _handleStockModeChange(StockMode value) {
if (config.updater != null)
config.updater(config.configuration.copyWith(stockMode: value));
if (widget.updater != null)
widget.updater(widget.configuration.copyWith(stockMode: value));
}
void _handleStockMenu(BuildContext context, _StockMenuItem value) {
@@ -148,7 +148,7 @@ class StockHomeState extends State<StockHome> {
title: const Text('Optimistic'),
trailing: new Radio<StockMode>(
value: StockMode.optimistic,
groupValue: config.configuration.stockMode,
groupValue: widget.configuration.stockMode,
onChanged: _handleStockModeChange,
),
onTap: () {
@@ -160,7 +160,7 @@ class StockHomeState extends State<StockHome> {
title: const Text('Pessimistic'),
trailing: new Radio<StockMode>(
value: StockMode.pessimistic,
groupValue: config.configuration.stockMode,
groupValue: widget.configuration.stockMode,
onChanged: _handleStockModeChange,
),
onTap: () {
@@ -234,7 +234,7 @@ class StockHomeState extends State<StockHome> {
}
Iterable<Stock> _getStockList(Iterable<String> symbols) {
return symbols.map((String symbol) => config.stocks[symbol])
return symbols.map((String symbol) => widget.stocks[symbol])
.where((Stock stock) => stock != null);
}
@@ -330,7 +330,7 @@ class StockHomeState extends State<StockHome> {
drawer: _buildDrawer(context),
body: new TabBarView(
children: <Widget>[
_buildStockTab(context, StockHomeTab.market, config.symbols),
_buildStockTab(context, StockHomeTab.market, widget.symbols),
_buildStockTab(context, StockHomeTab.portfolio, portfolioSymbols),
],
),

View File

@@ -19,48 +19,48 @@ class StockSettings extends StatefulWidget {
class StockSettingsState extends State<StockSettings> {
void _handleOptimismChanged(bool value) {
value ??= false;
sendUpdates(config.configuration.copyWith(stockMode: value ? StockMode.optimistic : StockMode.pessimistic));
sendUpdates(widget.configuration.copyWith(stockMode: value ? StockMode.optimistic : StockMode.pessimistic));
}
void _handleBackupChanged(bool value) {
sendUpdates(config.configuration.copyWith(backupMode: value ? BackupMode.enabled : BackupMode.disabled));
sendUpdates(widget.configuration.copyWith(backupMode: value ? BackupMode.enabled : BackupMode.disabled));
}
void _handleShowGridChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowGrid: value));
sendUpdates(widget.configuration.copyWith(debugShowGrid: value));
}
void _handleShowSizesChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowSizes: value));
sendUpdates(widget.configuration.copyWith(debugShowSizes: value));
}
void _handleShowBaselinesChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowBaselines: value));
sendUpdates(widget.configuration.copyWith(debugShowBaselines: value));
}
void _handleShowLayersChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowLayers: value));
sendUpdates(widget.configuration.copyWith(debugShowLayers: value));
}
void _handleShowPointersChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowPointers: value));
sendUpdates(widget.configuration.copyWith(debugShowPointers: value));
}
void _handleShowRainbowChanged(bool value) {
sendUpdates(config.configuration.copyWith(debugShowRainbow: value));
sendUpdates(widget.configuration.copyWith(debugShowRainbow: value));
}
void _handleShowPerformanceOverlayChanged(bool value) {
sendUpdates(config.configuration.copyWith(showPerformanceOverlay: value));
sendUpdates(widget.configuration.copyWith(showPerformanceOverlay: value));
}
void _handleShowSemanticsDebuggerChanged(bool value) {
sendUpdates(config.configuration.copyWith(showSemanticsDebugger: value));
sendUpdates(widget.configuration.copyWith(showSemanticsDebugger: value));
}
void _confirmOptimismChange() {
switch (config.configuration.stockMode) {
switch (widget.configuration.stockMode) {
case StockMode.optimistic:
_handleOptimismChanged(false);
break;
@@ -91,8 +91,8 @@ class StockSettingsState extends State<StockSettings> {
}
void sendUpdates(StockConfiguration value) {
if (config.updater != null)
config.updater(value);
if (widget.updater != null)
widget.updater(value);
}
Widget buildAppBar(BuildContext context) {
@@ -108,34 +108,34 @@ class StockSettingsState extends State<StockSettings> {
title: const Text('Everything is awesome'),
onTap: _confirmOptimismChange,
trailing: new Checkbox(
value: config.configuration.stockMode == StockMode.optimistic,
value: widget.configuration.stockMode == StockMode.optimistic,
onChanged: (bool value) => _confirmOptimismChange(),
),
),
new ListTile(
leading: const Icon(Icons.backup),
title: const Text('Back up stock list to the cloud'),
onTap: () { _handleBackupChanged(!(config.configuration.backupMode == BackupMode.enabled)); },
onTap: () { _handleBackupChanged(!(widget.configuration.backupMode == BackupMode.enabled)); },
trailing: new Switch(
value: config.configuration.backupMode == BackupMode.enabled,
value: widget.configuration.backupMode == BackupMode.enabled,
onChanged: _handleBackupChanged,
),
),
new ListTile(
leading: const Icon(Icons.picture_in_picture),
title: const Text('Show rendering performance overlay'),
onTap: () { _handleShowPerformanceOverlayChanged(!config.configuration.showPerformanceOverlay); },
onTap: () { _handleShowPerformanceOverlayChanged(!widget.configuration.showPerformanceOverlay); },
trailing: new Switch(
value: config.configuration.showPerformanceOverlay,
value: widget.configuration.showPerformanceOverlay,
onChanged: _handleShowPerformanceOverlayChanged,
),
),
new ListTile(
leading: const Icon(Icons.accessibility),
title: const Text('Show semantics overlay'),
onTap: () { _handleShowSemanticsDebuggerChanged(!config.configuration.showSemanticsDebugger); },
onTap: () { _handleShowSemanticsDebuggerChanged(!widget.configuration.showSemanticsDebugger); },
trailing: new Switch(
value: config.configuration.showSemanticsDebugger,
value: widget.configuration.showSemanticsDebugger,
onChanged: _handleShowSemanticsDebuggerChanged,
),
),
@@ -146,54 +146,54 @@ class StockSettingsState extends State<StockSettings> {
new ListTile(
leading: const Icon(Icons.border_clear),
title: const Text('Show material grid (for debugging)'),
onTap: () { _handleShowGridChanged(!config.configuration.debugShowGrid); },
onTap: () { _handleShowGridChanged(!widget.configuration.debugShowGrid); },
trailing: new Switch(
value: config.configuration.debugShowGrid,
value: widget.configuration.debugShowGrid,
onChanged: _handleShowGridChanged,
),
),
new ListTile(
leading: const Icon(Icons.border_all),
title: const Text('Show construction lines (for debugging)'),
onTap: () { _handleShowSizesChanged(!config.configuration.debugShowSizes); },
onTap: () { _handleShowSizesChanged(!widget.configuration.debugShowSizes); },
trailing: new Switch(
value: config.configuration.debugShowSizes,
value: widget.configuration.debugShowSizes,
onChanged: _handleShowSizesChanged,
),
),
new ListTile(
leading: const Icon(Icons.format_color_text),
title: const Text('Show baselines (for debugging)'),
onTap: () { _handleShowBaselinesChanged(!config.configuration.debugShowBaselines); },
onTap: () { _handleShowBaselinesChanged(!widget.configuration.debugShowBaselines); },
trailing: new Switch(
value: config.configuration.debugShowBaselines,
value: widget.configuration.debugShowBaselines,
onChanged: _handleShowBaselinesChanged,
),
),
new ListTile(
leading: const Icon(Icons.filter_none),
title: const Text('Show layer boundaries (for debugging)'),
onTap: () { _handleShowLayersChanged(!config.configuration.debugShowLayers); },
onTap: () { _handleShowLayersChanged(!widget.configuration.debugShowLayers); },
trailing: new Switch(
value: config.configuration.debugShowLayers,
value: widget.configuration.debugShowLayers,
onChanged: _handleShowLayersChanged,
),
),
new ListTile(
leading: const Icon(Icons.mouse),
title: const Text('Show pointer hit-testing (for debugging)'),
onTap: () { _handleShowPointersChanged(!config.configuration.debugShowPointers); },
onTap: () { _handleShowPointersChanged(!widget.configuration.debugShowPointers); },
trailing: new Switch(
value: config.configuration.debugShowPointers,
value: widget.configuration.debugShowPointers,
onChanged: _handleShowPointersChanged,
),
),
new ListTile(
leading: const Icon(Icons.gradient),
title: const Text('Show repaint rainbow (for debugging)'),
onTap: () { _handleShowRainbowChanged(!config.configuration.debugShowRainbow); },
onTap: () { _handleShowRainbowChanged(!widget.configuration.debugShowRainbow); },
trailing: new Switch(
value: config.configuration.debugShowRainbow,
value: widget.configuration.debugShowRainbow,
onChanged: _handleShowRainbowChanged,
),
),