我是新手,在尝试在 Appbar 上合并一个更改整个应用程序主题的按钮时遇到问题。
这是main.dart文件代码。
import 'package:flutter/material.dart';
import 'package:qrpay_app/routes/Routes.dart';
import 'module/splash/splash_view.dart';
import 'module/buy/buy_list_view.dart';
import 'module/sell/sell_list_view.dart';
import 'module/shop/shop_list_view.dart';
import 'module/account/account_list_view.dart';
import 'module/contact/contact_list_view.dart';
import 'module/help/help_list_view.dart';
import 'module/receipts/receipts_list_view.dart';
import 'module/about us/about_us_view.dart';
import 'package:qrpay_app/Themes/appThemes.dart';
import 'module/qr/qr_view.dart';
void main() {
runApp(new MaterialApp(
title: 'QRPAY Touch-Free',
theme: new ThemeData(primarySwatch: Colors.red),
home: SplashPage(),
routes: {
Routes.splash: (context) => SplashPage(),
Routes.buy: (context) => BuyPage(),
Routes.sell: (context) => SellPage(),
Routes.shop: (context) => ShopPage(),
Routes.qr: (context) => QRPage(),
Routes.account: (context) => AccountPage(),
Routes.contact: (context) => ContactPage(),
Routes.help: (context) => HelpPage(),
Routes.receipts: (context) => ReceiptsPage(),
Routes.about_us: (context) => AboutUsPage(),
},
));
}
这是appThemes.dart代码:
import 'package:flutter/material.dart';
class AppThemes {
// Simple constructor
AppThemes._();
static final ThemeData highContrast = ThemeData(
primarySwatch: Colors.black,
primaryTextTheme: TextTheme(
headline6: TextStyle(color: Colors.white),
),
scaffoldBackgroundColor: Colors.white,
appBarTheme: AppBarTheme(
color: Colors.black,
iconTheme: IconThemeData(
color: Colors.white,
),
elevation: 30.0,
),
);
static final ThemeData normalContrast = ThemeData(
scaffoldBackgroundColor: Colors.white,
appBarTheme: AppBarTheme(
color: Colors.red,
iconTheme: IconThemeData(
color: Colors.white,
),
),
);
}
我已将家路由到splash_view.dart。这是appThemes.dart代码:
import 'package:flutter/material.dart';
import 'package:qrpay_app/widget/drawer.dart';
import 'package:qrpay_app/Themes/appThemes.dart';
class SplashPage extends StatefulWidget {
static const String routeName = '/splash';
@override
_SplashPageState createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
void changeContrast() {
print("High contrast button clicked\nChanging app contrast\n");
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("QRPAY Touch-Free"),
elevation: 30.0,
actions: <Widget>[
ElevatedButton(
onPressed: () {
changeContrast();
},
child: Text('High Contrast')),
],
),
drawer: AppDrawer(),
body: new Center(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
child: new Image.asset(
'res/images/qplogo.png',
width: MediaQuery.of(context).size.width * .9,
fit: BoxFit.cover,
),
),
],
),
),
);
}
}
我添加了一个提升按钮,需要更改整个应用程序的主题。请帮助根据我的飞镖文件映射功能。
另外,我对如何添加状态更改感到困惑
我尝试与“提供者”一起锻炼,但我感到困惑。
请有人帮助我。另外,如果您需要其他任何东西来更好地理解我的问题,请告诉我。
感谢大家抽出时间帮助我。
谢谢你。