我是 flutter 新手,我创建了一个带有
Scaffold
的应用程序,其中包含 appBar、主体和抽屉。
我使用自定义颜色创建了自己的 ColorScheme。
现在,在我用作脚手架主体的小部件中,flutter 自动使用我的方案的“背景”颜色作为背景颜色,这很好。但对于该小部件内的
Text
组件,它使用 onSurface 颜色作为文本颜色。难道不应该使用 onBackground 颜色吗?
这是我的主要布局:
return LayoutBuilder(
builder: (context, constraints) {
ColorScheme scheme = Theme.of(context).colorScheme;
double imgWidth = min(constraints.maxWidth*0.5, constraints.maxHeight*0.2*1191/382);
double imgHeight = imgWidth/1191*382;
return Scaffold(
appBar: AppBar(title: Image.asset('assets/images/Logo.png', width: imgWidth), toolbarHeight: imgHeight+10, centerTitle: true,),
body: Center(
child: page,
),
drawer: Drawer(
child: SafeArea(
child: ListView(
padding: EdgeInsets.zero,
children: Utils.map(menu, (e,idx) => ListTile(
title: Text(e.name),
selected: idx == selectedIndex,
onTap: () {
setState(() {
selectedIndex = idx;
});
Navigator.pop(context);
},
)).toList()
),
),
),
);
}
);
以及我的默认页面的内容
return Center(
child: Column(
children: [
Text('Some Text:'),
],
),
);
onSurface
旨在提供与表面(背景)颜色的高对比度。
它确保文本可读,即使背景颜色不同。
您可以根据
onBackground
更改文本颜色
return Center(
child: Column(
children: [
Text(
'Some Text:',
style: TextStyle(color: Theme.of(context).colorScheme.onBackground),
),
],
),
);