第一次点击时在同一个按钮上更改文本大小,第二次点击时更改为默认大小

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"),
            ),
          ],
        ),
      ),
    );
  }
}