diff --git a/packages/flutter_tools/templates/create/lib/main.dart.tmpl b/packages/flutter_tools/templates/create/lib/main.dart.tmpl index a6119bbf20..2667917b6c 100644 --- a/packages/flutter_tools/templates/create/lib/main.dart.tmpl +++ b/packages/flutter_tools/templates/create/lib/main.dart.tmpl @@ -14,7 +14,6 @@ void main() { class MyApp extends StatelessWidget { // This widget is the root of your application. - // It is stateless, meaning that it always looks the same. @override Widget build(BuildContext context) { return new MaterialApp( @@ -30,18 +29,25 @@ class MyApp extends StatelessWidget { // reset back to zero -- the application is not restarted. primarySwatch: Colors.blue, ), - home: new MyHomePage(), + home: new MyHomePage(title: 'Flutter Demo'), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key key}) : super(key: key); + MyHomePage({Key key, this.title}) : super(key: key); // This widget is the home page of your application. It is stateful, // meaning that it has a State object (defined below) that contains // fields that affect how it looks. + // This class is the configuration for the state. It holds the + // values (in this case the title) provided by the parent (in this + // case the App widget) and used by the build method of the State. + // Fields in a Widget subclass are always marked "final". + + final String title; + @override _MyHomePageState createState() => new _MyHomePageState(); } @@ -65,7 +71,10 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( - title: new Text('Flutter Demo'), + // Here we take the value from the MyHomePage object that + // was created by the App.build method, and use it to set + // our appbar title. + title: new Text(config.title), ), body: new Center( child: new Text(