简体   繁体   English

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

[英]On the same button when tap first time change the size of text,when tap second time changes to default

trying to change the text size in textfield dynamically using a single button.尝试使用单个按钮动态更改文本字段中的文本大小。 already used setstate but it changes only single time.已经使用 setstate 但它只更改一次。 do not know how to change it again on second tap不知道如何在第二次点击时再次更改它

and use this you can change the font size of textfield并使用它可以更改文本字段的字体大小

  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"),
            ),

for full example完整的例子

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM