[英]Flutter/Android change background color of Gesture Navigation icon
Thats the primary color you can change it like this那是原色,您可以像这样更改它
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.lightGreen,//here.change this one
),
)
It isn't from Android.它不是来自 Android。 Flutter's MaterialApp already provides a set of attributes for us, including a Prymary Color, ColorScheme, etc. The reason is obvious, if every developer had to write every theme aspect in every widget coding would be awful.
Flutter 的 MaterialApp 已经为我们提供了一组属性,包括 Prymary Color、ColorScheme 等。原因很明显,如果每个开发人员都必须在每个小部件编码中编写每个主题方面,那就太糟糕了。 So Material widgets look for a theme, which Material will provide as default, if we don't overide it.
因此,Material 小部件会寻找一个主题,如果我们不覆盖它,Material 将默认提供该主题。
Know this, the solution is:知道这一点,解决办法是:
Text( "some text", style: TextStyle())
(note the TextStyle ), but this logic is apllied to a bunch of other widgets too, including buttons.Text( "some text", style: TextStyle())
(注意TextStyle )时,在 Text 小部件中很常见,但这种逻辑也适用于许多其他小部件,包括按钮。 Disavantage of this is that you have to manual change every widget, so no auto darkmode and painfull design changes for reasonable size apps. Example of what I meant by overiding the default Theme of your App:我的意思是覆盖应用程序的默认主题的示例:
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Association App for AMDKP Integrated Plataform',
theme: ThemeData(
colorScheme: ColorScheme(
brightness: Brightness.light,
primary: consts.golden1,
onPrimary: consts.black41,
secondary: Colors.green.shade500,
onSecondary: Colors.green.shade300,
background: consts.greyWhite,
onBackground: consts.black41,
surface: Colors.white,
onSurface: Colors.black45,
error: Colors.red.shade900,
onError: Colors.red.shade900,
),
primarySwatch: Colors.blue,
primaryColor: consts.golden1,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
shadowColor: consts.black41,
primary: Theme.of(context).colorScheme.onSurface.withAlpha(150),
onPrimary: Theme.of(context).colorScheme.surface,
)),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.white.withAlpha(230),
backgroundColor: Colors.black87.withAlpha(170),
textStyle: Theme.of(context).textTheme.bodyMedium,
padding: const EdgeInsets.symmetric(horizontal: 10.0),
)),
inputDecorationTheme: const InputDecorationTheme(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: consts.golden1, width: 2)),
),
),
home: const HomePage(),
So definitely take a look at flutter themes, it will empower your flutter developer skills and you will benefit a lot by using it anyway: :) Cheers所以一定要看看 flutter 主题,它将增强您的 flutter 开发人员技能,无论如何使用它您都会受益匪浅::) 干杯
I am also having this issue.我也有这个问题。 As a work around, I keep the Material App ThemeData's primary color as white.
作为解决方法,我将 Material App ThemeData 的原色保留为白色。 Then used the Theme widget to override my page theme to use my custom theme.
然后使用主题小部件覆盖我的页面主题以使用我的自定义主题。
https://api.flutter.dev/flutter/material/ThemeData-class.html https://api.flutter.dev/flutter/material/ThemeData-class.html
class MyApp extends StatelessWidget { final _navigatorKey = GlobalKey<NavigatorState>(); NavigatorState? get _navigator => _navigatorKey.currentState; MyApp({super.key}); // App Routing Route<dynamic> _generateRoute(RouteSettings settings) { Widget newPage = Container(); switch (settings.name) { case AppRoutes.welcome: newPage = const WelcomePage(); break; case AppRoutes.login: newPage = LoginPage(); break; } return FadeRoute( page: Theme( data: lightTheme, child: newPage, ), ); } // This widget is the root of your application. @override Widget build(BuildContext context) { return MultiBlocProvider( providers: [ BlocProvider<AppBloc>( create: (_) => AppBloc()..add(InitializeAppEvent())), BlocProvider<AuthBloc>(create: (_) => AuthBloc()) ], child: BlocListener<AuthBloc, AuthState>( listener: (_, state) { if (state is Authenticated) { // Go to Main Page _navigator?.pushReplacementNamed(AppRoutes.home); } else { // Go to Login Page _navigator?.pushReplacementNamed(AppRoutes.login); } }, child: MaterialApp( navigatorKey: _navigatorKey, title: 'Flutter Demo', theme: ThemeData(primaryColor: Colors.white), initialRoute: AppRoutes.welcome, onGenerateRoute: _generateRoute, ))); } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.