我遇到过与https://github.com/flutter/flutter/issues/100067中讨论的问题相同的问题我能够得到flutter Webview。但我需要改变颜色从浅绿色到蓝色,如底部导航栏中的加号按钮所示。请帮助。
gajydyqb1#
尝试以下代码,参考showDatePicker
builder: (context, child) { return Theme( data: Theme.of(context).copyWith( colorScheme: const ColorScheme.light( primary: Colors.indigo,//add your + button color here ), textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( foregroundColor: Colors.indigo, // button text color ), ), ), child: child!, ); },
完整代码:
import 'dart:async'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key? key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { DateTime selectedDate = DateTime.now(); Future<void> _selectDate(BuildContext context) async { final DateTime? picked = await showDatePicker( context: context, initialDate: selectedDate, firstDate: DateTime(2015, 8), lastDate: DateTime(2101), builder: (context, child) { return Theme( data: Theme.of(context).copyWith( colorScheme: const ColorScheme.light( primary: Colors.indigo, ), textButtonTheme: TextButtonThemeData( style: TextButton.styleFrom( foregroundColor: Colors.indigo, // button text color ), ), ), child: child!, ); }, ); if (picked != null && picked != selectedDate) { setState(() { selectedDate = picked; }); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Datepicker'), ), body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: <Widget>[ Text("${selectedDate.toLocal()}".split(' ')[0]), SizedBox( height: 20.0, ), ElevatedButton( onPressed: () => _selectDate(context), child: Text('Select date'), ), ], ), ), ); } }
结果-〉
c9qzyr3d2#
参考issue和配置1.打开应用程序的build.gradle文件。1.确保存储库部分包含Google的Maven存储库google()。例如:
build.gradle
allprojects { repositories { google() centre() } }
将库添加到依赖项部分:
dependencies { // ... implementation 'com.google.android.material:material:1.7' // ... }
1.在/android/app/src/main/res/values/styles.xml中设置灯光主题:内容_副本更改到
<style name="NormalTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
1.在/android/app/src/main/res/values-night/styles. xml中设置黑暗主题content_copy change到
<style name="NormalTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
2条答案
按热度按时间gajydyqb1#
尝试以下代码,参考showDatePicker
完整代码:
结果-〉
c9qzyr3d2#
参考issue和配置
1.打开应用程序的
build.gradle
文件。1.确保存储库部分包含Google的Maven存储库google()。例如:
将库添加到依赖项部分:
1.在/android/app/src/main/res/values/styles.xml中设置灯光主题:内容_副本更改
到
1.在/android/app/src/main/res/values-night/styles. xml中设置黑暗主题content_copy change
到