flutter - Flutter中如何实现字体大小调整对话框?
问题描述
我是新来的。我从这个应用程序https://play.google.com/store/apps/details?id=com.nikitadev.usconstitution&hl=en中获得了灵感,我正在用颤振实现字体大小调整对话框。我真的被困住了。
解决方案
制作静态变量并使用默认主题中的值。当字体大小增加时,将该变量的值设置为此字体大小。
//Initialize a variable at the top to change
double _textDefaultSize = 16;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
bodyText1: TextStyle(
fontSize: _textDefaultSize,
//Use the text Size in the main theme
),
),
),
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
title: Text("TextColor checking"),
),
body: Center(
child: Column(
children: <Widget>[
Text(
"Example Text",
style: TextStyle(fontSize: _textDefaultSize),
//Use the font size in all texts
),
FlatButton(
onPressed: () {
setState() {
_textDefaultSize++; //Change the value of variable here
}
},
child: Text("Increase Size"),
),
FlatButton(
onPressed: () {
setState() {
_textDefaultSize--; //Change the value of variable here
}
},
child: Text("Increase Size"),
),
],
),
),
),
);
}
}
```
推荐阅读
- datetime - 如何在 Apostrophe CMS 中的 Nunjucks 模板中获取当前年份
- laravel - 使用 JMeter 测试登录到 Laravel 站点
- angular - Angular 8:在鼠标单击事件后使用 HostListener 查找 DOM 元素
- reactjs - React Native:什么情况下需要手动添加依赖的依赖?
- python - PyMongo:如何在 MongoDB 中批量更新大量 JSON 数据
- javascript - 如何使用 c# 或 jQuery 或 Javascript 获取客户端系统/PC 域名和 PC 名称
- php - PHP 警告:mail():找到数字标头
- javascript - 将父 ID 信息添加到层次结构中的属性
- c# - Revit C#跳过加载pyrevit
- asp.net-core - 如何使用 .Net Core MVC Identity 实现 Google Drive API