import 'package:flutter/material.dart';
void main() {
runApp( MaterialApp(
debugShowCheckedModeBanner:false,//隐藏debug标志
home: MyHome(),
theme: ThemeData(
primarySwatch: Colors.green,//基础样本
accentColor: Colors.lightGreenAccent,//重点色
backgroundColor: Colors.black12,//背景色
),
));
}
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Using Theme"),
),
body: Container(
// 另一种设置控件背景颜色的方法
decoration: BoxDecoration(color: Colors.black87),//body的颜色
child: Center(
child: Container(
// 使用主题重点色作为背景色
color: Theme.of(context).accentColor,//文字容器的颜色
child: Text(
'Hello World!',
// 使用主题标题的字体和字体大小
style: Theme.of(context).textTheme.title,
),
),
),
),
floatingActionButton: Theme(
// 重写当前控件的"主题的重点色"
data: Theme.of(context).copyWith(accentColor: Colors.pinkAccent),
child: FloatingActionButton(
onPressed: null,
child: Icon(Icons.add),
),
),
);
}
}