【问题标题】:On the same button when tap first time change the size of text,when tap second time changes to default第一次点击时在同一个按钮上更改文本大小,第二次点击时更改为默认值
【发布时间】:2021-04-14 18:52:02
【问题描述】:

尝试使用单个按钮动态更改文本字段中的文本大小。已经使用 setstate 但它只更改一次。不知道如何在第二次点击时再次更改它

【问题讨论】:

  • 默认是全局的,比如假设每个文本视图的默认值为 12sp?还是默认为那个特定的文本视图,所以每个文本视图都有自己的默认大小与其他的不同?
  • 保持一个布尔值然后点击检查布尔值并用不同的文本大小重复你的代码

标签: android flutter dart frontend flutter-test


【解决方案1】:

并使用它可以更改文本字段的字体大小

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

【讨论】:

    猜你喜欢
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 2017-07-03
    相关资源
    最近更新 更多