我正在try 制作一个TextFormField,以便在currency_text_input_formatter包裹中输入钱.我把它放在showModalBottomSheet.

这就是我打开showModalBottomSheet的时候发生的事情:

enter image description here

使用键盘进行更改时:

enter image description here

正如你所看到的,这一次TRY元货币的图标已经到来.当我打开showModalBottomSheet时,我希望TRY货币图标出现.我需要在键盘上做一个更改,以便显示实际货币TRY.当showModalBottomSheet打开时,我希望它正确显示(TRY)图标.

我怎样才能解决这个问题?

textFormField码:

TextFormField(
  style: TextStyle(fontSize: 19),
  decoration: InputDecoration(
    border: OutlineInputBorder(),
  ),
  initialValue: _fiyat.format(snapshot.data!.docs[index].data()["urunFiyati"]),
  inputFormatters: <TextInputFormatter>[
    CurrencyTextInputFormatter(
      locale: 'tr_TR',
      decimalDigits: 2,
      symbol: '₺',
    ),
  ],
  keyboardType: TextInputType.number,
),

提前感谢您的帮助:)

推荐答案

try 在生成之前初始化CurrencyTextInputFormatter(构建上下文).UPD:代码已更新,因此也使用showModalBottomSheet

import 'package:flutter/material.dart';
import 'package:currency_text_input_formatter/currency_text_input_formatter.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return  MaterialApp(home: HomePage());
  }
}

class HomePage extends StatelessWidget {
   HomePage({Key? key}) : super(key: key);
  final CurrencyTextInputFormatter _formatter = CurrencyTextInputFormatter(
    locale: 'tr_TR',
    decimalDigits: 2,
    symbol: '₺',
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: ElevatedButton(
          child: const Text('showModalBottomSheet'),
          onPressed: () {
            showModalBottomSheet<void>(
              context: context,
              builder: (BuildContext context) {
                return Container(
                  height: 200,
                  color: Colors.grey[100],
                  child: Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.symmetric(horizontal: 30,vertical: 10),
                          child: TextFormField(
                            initialValue: _formatter.format('2000'),
                            inputFormatters: <TextInputFormatter>[_formatter],
                            keyboardType: TextInputType.number,
                          ),
                        ),
                        const Text('Modal BottomSheet'),
                        ElevatedButton(
                          child: const Text('Close BottomSheet'),
                          onPressed: () => Navigator.pop(context),
                        )
                      ],
                    ),
                  ),
                );
              },
            );
          },
        ),
      )
    );
  }
}

Flutter相关问答推荐

手势捕获的异常:类型';Double';不是类型转换中类型';Double';的子类型

在Flutter 中创建自定义Snackbar类

Flutter BLoC et workmanager:如何创建独特的仓库初始化模式?

如何将Xpriter代码页更改为代码页27?

如何在表格日历标题下方添加文本?

Firebase动态链接已弃用,不应在新项目中使用.Flutter 替代方案

就像Flutter 中的头文件一样?

Flex ListView用于可滚动和响应的页面

BoxConstraints强制使用无限宽度(列中的Listview)

上传的图像不能在FireBase中预览.S档案类型为空白,摆动

如何在flutter中使用youtube_explod_start加载下一页

如何在flutter中将所有单词的第一个字母大写

Flutter 使用扩展的 TextField 定位小部件

启动画面中的淡入淡出图像

在向 Google Route API 发送 HTTP Post 请求期间发生错误,

在不丢失游戏状态的情况下从 Flame 游戏导航到 Flutter 小部件

如何获得Flutter 的时差?

Flutter:如何判断嵌套列表是否包含值

小部件库捕获的 Flutter 异常

如何解决Flutter /dart 后期的问题