From 11fa94cd6b19f73d3d0d2af5dbaf7354244d77ff Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 26 Feb 2016 13:31:30 -0800 Subject: [PATCH] Simplify demo template We don't need these keys. Also, improve style in several places. Fixes #2225 --- .../src/material/floating_action_button.dart | 30 +++++++++++++------ .../templates/create/lib/main.dart.tmpl | 13 ++++---- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index 8e5b65fc46..7abd7f38d8 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -9,6 +9,7 @@ import 'icon_theme_data.dart'; import 'ink_well.dart'; import 'material.dart'; import 'theme.dart'; +import 'tooltip.dart'; // TODO(eseidel): This needs to change based on device size? // http://www.google.com/design/spec/layout/metrics-keylines.html#metrics-keylines-keylines-spacing @@ -35,6 +36,7 @@ class FloatingActionButton extends StatefulComponent { const FloatingActionButton({ Key key, this.child, + this.tooltip, this.backgroundColor, this.elevation: 6, this.highlightElevation: 12, @@ -43,6 +45,7 @@ class FloatingActionButton extends StatefulComponent { }) : super(key: key); final Widget child; + final String tooltip; final Color backgroundColor; /// The callback that is invoked when the button is tapped or otherwise activated. @@ -99,6 +102,23 @@ class _FloatingActionButtonState extends State { iconThemeColor = themeData.accentColorBrightness == ThemeBrightness.dark ? IconThemeColor.white : IconThemeColor.black; } + Widget result = new Center( + child: new IconTheme( + data: new IconThemeData(color: iconThemeColor), + child: new RotationTransition( + turns: _childSegue, + child: config.child + ) + ) + ); + + if (config.tooltip != null) { + result = new Tooltip( + message: config.tooltip, + child: result + ); + } + return new Material( color: materialColor, type: MaterialType.circle, @@ -109,15 +129,7 @@ class _FloatingActionButtonState extends State { child: new InkWell( onTap: config.onPressed, onHighlightChanged: _handleHighlightChanged, - child: new Center( - child: new IconTheme( - data: new IconThemeData(color: iconThemeColor), - child: new RotationTransition( - turns: _childSegue, - child: config.child - ) - ) - ) + child: result ) ) ); diff --git a/packages/flutter_tools/templates/create/lib/main.dart.tmpl b/packages/flutter_tools/templates/create/lib/main.dart.tmpl index b455df2318..a2cbbc0e56 100644 --- a/packages/flutter_tools/templates/create/lib/main.dart.tmpl +++ b/packages/flutter_tools/templates/create/lib/main.dart.tmpl @@ -12,7 +12,7 @@ void main() { } class FlutterDemo extends StatefulComponent { - State createState() => new _FlutterDemoState(); + _FlutterDemoState createState() => new _FlutterDemoState(); } class _FlutterDemoState extends State { @@ -30,17 +30,14 @@ class _FlutterDemoState extends State { center: new Text('Flutter Demo') ), body: new Center( - child: new Text( - 'Button tapped $_counter times.', - key: const ValueKey('counter') - ) + child: new Text('Button tapped $_counter time${ _counter == 1 ? '' : 's' }.') ), floatingActionButton: new FloatingActionButton( - key: const ValueKey('fab'), + onPressed: _incrementCounter, + tooltip: 'Increment', child: new Icon( icon: 'content/add' - ), - onPressed: _incrementCounter + ) ) ); }