![](/img/trans.png)
[英]Flutter | How can I change my FloatingActionButton background color to transparent?
[英]Flutter - How can I change the background color of LicensePage?
我想將除LicensePage
之外的每個屏幕的背景顏色設置為某種顏色,因此我通過MaterialApp
的theme
參數指定了scaffoldBackbroundColor
BackbroundColor,如下所示。
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(scaffoldBackgroundColor: Colors.blue.shade200),
home: HomeScreen(),
);
}
}
這也改變了許可證頁面的背景顏色,所以為了將它改回白色,我嘗試覆蓋scaffoldBackbroundColor
,但它不起作用。
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Theme(
data: Theme.of(context).copyWith(scaffoldBackgroundColor: Colors.white),
child: Center(
child: RaisedButton(
child: const Text('Show licenses'),
onPressed: () => showLicensePage(context: context),
),
),
),
);
}
}
我該怎么做?
就我而言,我發現 ThemeData(cardColor) 是在指定 LicensePage 背景顏色。 所以,
showLicense(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => Theme(
data: ThemeData(
cardColor: Colors.yellow,
),
child: LicensePage(
applicationVersion: '0.1',
applicationIcon: Icon(Icons.person),
applicationLegalese: 'Legal stuff',
),
),
),
);
}
我想出了這個,它成功地工作了。
Scaffold(
body: Center(
child: RaisedButton(
child: const Text('Show licenses'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => Theme(
data: Theme.of(context).copyWith(
scaffoldBackgroundColor: Colors.white,
),
child: LicensePage(...),
),
),
),
),
),
)
這樣你就不能設置主題,使用Container
設置顏色
Scaffold(
body: Container(
color: Colors.white,
child: Center(
child: RaisedButton(
child: const Text('Show licenses'),
onPressed: () => showLicensePage(context: context),
),
),
),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.