mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-07-15 02:46:03 +08:00
updated: using_theme example
This commit is contained in:
BIN
using_theme/demo_img.jpg
Executable file → Normal file
BIN
using_theme/demo_img.jpg
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 12 KiB |
@ -2,28 +2,51 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new MaterialApp(
|
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
|
||||||
appBar: new AppBar(
|
appBar: new AppBar(
|
||||||
// AppBar Title
|
// AppBar Title
|
||||||
title: new Text("Using Theme"),
|
title: new Text("Using Theme"),
|
||||||
),
|
),
|
||||||
body: new Container(
|
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(
|
child: new Text(
|
||||||
"Hello World!",
|
'Hello World!',
|
||||||
// Set the text style, text color to white
|
// Set text style as per theme
|
||||||
style: new TextStyle(color: Colors.white),
|
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,
|
floatingActionButton: new Theme(
|
||||||
theme: new ThemeData(
|
// override the accent color of theme for this widget only
|
||||||
primarySwatch: Colors.blue,
|
data: Theme.of(context).copyWith(accentColor: Colors.pinkAccent),
|
||||||
accentColor: Colors.lightBlueAccent,
|
child: new FloatingActionButton(
|
||||||
backgroundColor: Colors.blueAccent,
|
onPressed: null,
|
||||||
),
|
child: new Icon(Icons.add),
|
||||||
));
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user