如何解决颤振日期选择器中的溢出错误?
我正在使用日期选择器,但它显示了一个奇怪的溢出文本溢出错误。
我知道日期选择器使用应用程序主题进行样式设置。但是不知道在对话框中使用哪个Theme属性设置样式。
我的日期选择器:-
showDatePicker(
ontext: context,initialDate: DateTime.now(),firstDate: DateTime.now(),astDate: DateTime.utc(2100,DateTime.now().month,DateTime.now().day),);
我的应用主题:-
ThemeData(
primaryColor: Color(0xffE6F5F1),accentColor: Color(0xFF4EB799),visualDensity: VisualDensity.adaptivePlatformDensity,scaffoldBackgroundColor: Colors.white,textTheme: TextTheme(
headline2: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 96,letterSpacing: -1.5,fontFamily: "Muli",),headline3: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 60,letterSpacing: -0.5,headline4: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 48,letterSpacing: 0,headline5: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 34,letterSpacing: 0.25,subtitle1: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 24,headline6: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 20,letterSpacing: 0.15,subtitle2: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 18,bodyText2: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 16,letterSpacing: 0.5,bodyText1: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 14,button: const TextStyle(
fontWeight: FontWeight.w500,letterSpacing: 1.25,caption: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 12,letterSpacing: 0.4,overline: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 10,letterSpacing: 1.5,);
这是怎么回事,在主题选择器中如何设置样式的主题属性?
解决方法
在源代码date_picker_dialog.dart
中landscape
模式使用headline5
portrait
模式使用headline4
final TextStyle dateStyle = orientation == Orientation.landscape
? textTheme.headline5?.copyWith(color: dateColor)
: textTheme.headline4?.copyWith(color: dateColor);
...
final Widget header = DatePickerHeader(
helpText: widget.helpText ?? localizations.datePickerHelpText,titleText: dateText,titleStyle: dateStyle,orientation: orientation,isShort: orientation == Orientation.landscape,icon: entryModeIcon,iconTooltip: entryModeTooltip,onIconPressed: _handleEntryModeToggle,);
工作演示
完整代码可减少headline4
字体大小
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',theme: ThemeData(
primaryColor: Color(0xffE6F5F1),accentColor: Color(0xFF4EB799),visualDensity: VisualDensity.adaptivePlatformDensity,scaffoldBackgroundColor: Colors.white,textTheme: TextTheme(
headline2: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 96,letterSpacing: -1.5,fontFamily: "Muli",),headline3: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 60,letterSpacing: -0.5,headline4: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 30,letterSpacing: 0,headline5: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 34,letterSpacing: 0.25,subtitle1: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 24,headline6: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 20,letterSpacing: 0.15,subtitle2: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 18,bodyText2: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 16,letterSpacing: 0.5,bodyText1: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 14,button: const TextStyle(
fontWeight: FontWeight.w500,letterSpacing: 1.25,caption: const TextStyle(
fontWeight: FontWeight.w400,fontSize: 12,letterSpacing: 0.4,overline: const TextStyle(
fontWeight: FontWeight.w500,fontSize: 10,letterSpacing: 1.5,home: MyHomePage(title: 'Flutter Demo Home Page'),);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key,this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
showDatePicker(
context: context,initialDate: DateTime.now(),firstDate: DateTime.now(),lastDate: DateTime.utc(2100,DateTime.now().month,DateTime.now().day),);
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
Text(
'You have pushed the button this many times:',Text(
'$_counter',style: Theme.of(context).textTheme.headline4,],floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,tooltip: 'Increment',child: Icon(Icons.add),);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。