[英]On the same button when tap first time change the size of text,when tap second time changes to default
嘗試使用單個按鈕動態更改文本字段中的文本大小。 已經使用 setstate 但它只更改一次。 不知道如何在第二次點擊時再次更改它
並使用它可以更改文本字段的字體大小
double fSize=16;
TextFormField(
style: TextStyle(fontSize: fSize),
decoration: InputDecoration(
labelText: 'Custom Text',
),
),
RaisedButton(
onPressed: () {setState(() {
fSize = fSize == 16 ? 32: 16;
});},
child: Text("change size"),
),
完整的例子
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
@override
_PrivacyPolicyState createState() => _TestState();
}
class _TestState extends State<Test> {
double fSize=16;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
padding: EdgeInsets.fromLTRB(24, 16, 24, 0),
child: Column(
children: [
TextFormField(
style: TextStyle(fontSize: fSize),
decoration: InputDecoration(
labelText: 'Custom Text',
),
),
RaisedButton(
onPressed: () {setState(() {
fSize = fSize == 16 ? 32: 16;
});},
child: Text("change size"),
),
],
),
),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.