1.primarySwatch 和primaryColor
这个属性设置导航栏颜色
Widget build(BuildContext context) {
return new MaterialApp(
title: 'MyApp',
theme: ThemeData(
// primarySwatch 和primaryColor
primaryColor: Colors.white,
),
home: new BottomNavigationWidget(),
);
使用primaryColor可以COlors.white,使用primarySwatch不可以设置白色.(具体原因稍后更新)
2.ThemeData与MaterialApp关系
当你在main.dart里面设置了MaterialApp了,那就不需要在其他的界面里面return MaterialApp了,只需要return Scaffold就ok了,如下(具体原因稍后更新)
main.dart
import 'package:flutter/material.dart';
import 'index/index.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'MyApp',
theme: ThemeData(
// primarySwatch 和primaryColor
primaryColor: Colors.white,
),
home: new BottomNavigationWidget(),
);
}
}
home.main
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('首页'),
),
body: new Center(
child: new Text('首页'),
),
);
}
}