【发布时间】:2019-10-18 19:19:46
【问题描述】:
我在下面有一小段代码。它应该以蓝色显示“添加图标”。相反,它显示黑色按钮(在 MaterialApp 中作为强调颜色)。 我在“floatingActionButton”中做错了吗?
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
final appName = "Custom Themes";
return new MaterialApp(
title: appName,
theme: new ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.red[300],
accentColor: Colors.black,
),
home: new MyHomePage(
title: appName
),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
MyHomePage({Key key, @required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
appBar: AppBar(
title: new Text(title),
),
body: new Center(
child: new Container(
color: Theme.of(context).primaryColor,
child: new Text(
"Text with background color",
style: Theme.of(context).textTheme.title,
),
),
),
floatingActionButton: new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.blue),
child: new FloatingActionButton(
onPressed: null,
child: new Icon(Icons.add),
),
)
);
}
}
我看了一个教程(它在 iOS 中很流畅),那里的一切都像魅力一样。 Tut 是从 2019 年 4 月开始的。也许从那时起发生了一些变化?
【问题讨论】:
-
为什么不给图标添加颜色?喜欢
Icon(Icons.add, color:Colors.blue) -
它只改变图标的颜色而不是按钮的颜色。按钮仍然是黑色的。
-
好的,你想改变FAB的背景颜色,使用
backgroundColors: Colors.blue作为FAB属性