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('首頁'),
),
);
}
}