У меня есть приложение для материала, которое использует тему, основанную на светлой теме.Я изменяю scaffoldBackgroundColor на определенный цвет, который, кажется, не принимает.Фон на странице черный, а не серый.
метод build () приложения, которое идентифицирует это приложение как MaterialApp:
Widget build(BuildContext context) {
return new MaterialApp(
title: '???',
theme: appTheme,
routes: {
AppRoutes.login: (context) {
return new LoginPage(
authenticator: authenticate,
);
},
AppRoutes.home: (context) {
return new HomePage(
appState: appState,
accountRepository: widget.accountRepository,
authRepository: widget.authRepository,
);
},
},
);
}
Тема - здесь я повторно использую светлую темув качестве основы для моей новой темы, которая меняет scaffoldBackgroundColor на собственный цвет:
const coolGreyHi = const Color.fromARGB(40,30,20,66);
final ThemeData appTheme = _buildAppTheme();
ThemeData _buildAppTheme() {
final ThemeData base = new ThemeData.light();
return base.copyWith(
scaffoldBackgroundColor: coolGreyHi,
inputDecorationTheme: new InputDecorationTheme(
border: new OutlineInputBorder(),
)
);
}
метод построения страницы, где фон должен быть серым:
Widget build(BuildContext context) {
return new Scaffold(
body: new SafeArea(
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Padding(
padding: const EdgeInsets.fromLTRB(40.0, 0.0, 40.0, 0.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Image.asset('images/image.png'),
new SizedBox(height: 40.0),
new TextField(
controller: _uidTextController, decoration: new InputDecoration(
hintText: "you@yourdomain.com",
labelText: "Email Address",
),
),
new SizedBox(height: 12.0),
new TextField(
controller: _pwdTextController, decoration: new InputDecoration(
hintText: "Password",
labelText: "Password",
),
),
new SizedBox(height: 12.0),
new ButtonBar(
children: <Widget>[
new FlatButton(
child: new Text("SIGN UP"),
onPressed: () {},
),
new RaisedButton(
child: new Text("SIGN IN"),
elevation: 8.0,
onPressed: () {
authenticator(_uidTextController.text, _pwdTextController.text).then((bool isAuthenticated) {
if (isAuthenticated)
Navigator.of(context).pushNamedAndRemoveUntil(AppRoutes.home, (Route<dynamic> route) => false);
});
},
),
],
),
],
),
),
],
),
),
),
);
}