diff --git a/using_theme/demo_img.jpg b/using_theme/demo_img.jpg old mode 100755 new mode 100644 index 21fa3b4..eafc579 Binary files a/using_theme/demo_img.jpg and b/using_theme/demo_img.jpg differ diff --git a/using_theme/lib/main.dart b/using_theme/lib/main.dart index 23e6840..5cc161b 100644 --- a/using_theme/lib/main.dart +++ b/using_theme/lib/main.dart @@ -2,28 +2,51 @@ import 'package:flutter/material.dart'; void main() { runApp(new MaterialApp( - home: new Scaffold( + debugShowCheckedModeBanner: false, + home: new MyHome(), + // Set the theme's primary color, accent color, + theme: new ThemeData( + primarySwatch: Colors.green, + accentColor: Colors.lightGreenAccent, + // Set background color + backgroundColor: Colors.black12, + ), + )); +} + +class MyHome extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new Scaffold( // AppBar appBar: new AppBar( // AppBar Title title: new Text("Using Theme"), ), body: new Container( - child: new Center( + // Another way to set the background color + decoration: new BoxDecoration(color: Colors.black87), + child: new Center( + child: new Container( + // use the theme accent color as background color for this widget + color: Theme.of(context).accentColor, child: new Text( - "Hello World!", - // Set the text style, text color to white - style: new TextStyle(color: Colors.white), + 'Hello World!', + // Set text style as per theme + style: Theme.of(context).textTheme.title, ), ), - // Another way to set the background color - decoration: new BoxDecoration(color: Colors.lightBlueAccent)), - ), - // Set the theme's primary color, accent color, - theme: new ThemeData( - primarySwatch: Colors.blue, - accentColor: Colors.lightBlueAccent, - backgroundColor: Colors.blueAccent, - ), - )); + ), + ), + + floatingActionButton: new Theme( + // override the accent color of theme for this widget only + data: Theme.of(context).copyWith(accentColor: Colors.pinkAccent), + child: new FloatingActionButton( + onPressed: null, + child: new Icon(Icons.add), + ), + ), + ); + } }