草庐IT

input - Flutter输入装饰后缀图标不出现但一直显示十字符号

coder 2023-07-23 原文

我有以下示例代码。我现在已经设法放置了 prefixicon 并且它工作正常。我想将相同的图标移动到右侧的后缀含义,但它不起作用,但出现了 X 符号。 这是一个屏幕截图。

我添加了以下几行 suffixIcon: IconButton( 但它似乎没有出现,但左侧的前缀看起来非常好。我无法获得右侧的那个。是什么阻止了它从出现?

下面是我的代码。

class MyHomePageState extends State<MyHomePage> {
  // Show some different formats.
  final formats = {
    //InputType.both: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
    //InputType.date: DateFormat('dd/MM/yyyy'),
    //InputType.time: DateFormat("HH:mm"),
    InputType.date: DateFormat("d MMMM  yyyy"),
  };
  //InputType.date: DateFormat('yyyy-MM-dd'),
  // Changeable in demo
  InputType inputType = InputType.date;
  bool editable = true;
  DateTime date;

  @override
  Widget build(BuildContext context) => Scaffold(
      appBar: AppBar(title: Text(appName)),
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: ListView(
          children: <Widget>[

            Form(
          //key: _myKey,
          child: Column(
             children : [

              new Container(              
                width: 200.0,
                child:new DateTimePickerFormField(

                            dateOnly: true,
                            format: formats[inputType],
                            editable: false,
                            validator: (val) {
                              if (val != null) {
                                return null;
                              } else {
                                return 'Date Field is Empty';
                              }
                            },
                            /*decoration: InputDecoration(
                              border: InputBorder.none,
                              labelText: 'From',contentPadding: const EdgeInsets.symmetric(horizontal: 20.0)),*/
                          decoration: InputDecoration(
                  hintText: 'To',
                  border: InputBorder.none,
                  filled: false,
                  prefixIcon: Icon(
                    Icons.arrow_drop_down,
                    color: Colors.blue,
                    size: 28.0,
                  ),
                  suffixIcon: IconButton(
                      icon: Icon(Icons.arrow_drop_down,size: 28),
                      onPressed: () {
                        debugPrint('222');
                      })),
                   initialValue: DateTime.now().subtract(new Duration(days: 7)), //Add this in your Code.

                  ),

              )
             ]


          ),
        ),
        RaisedButton(
          onPressed: () {
            /*if (_myKey.currentState.validate()) {
              _myKey.currentState.save();
            } else {
            }*/ print("check;");
            if(emailController.text.isEmpty){
              print("TEST;");
                //valid = false;
                //emailError = "Email can't be blank!";
                //openAlertBox();
                Toast.show("Empty Date From", context, backgroundColor: Colors.red );

            } 
            else{
              print("not empty;");
              final f = new DateFormat('yyyy-MM-dd');
              final original = new DateFormat('d MMMM  yyyy');

              print("Format datre is"+emailController.text);
              print("Formate date :"+original.parse(emailController.text).toString());



            }
          },
          child: Text('Submit'),
        )

          ],
        ),
      ));

最佳答案

我通过仅挑出您提供的 TextFormField 代码重新创建了您的案例,并且能够将 下拉箭头 视为 suffixIcon

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
        height: MediaQuery
            .of(context)
            .size
            .height,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
            children : [
              new Container(
                color: Colors.yellow,
                width: 200.0,
                  child: TextFormField(
                  decoration: InputDecoration(
                      hintText: 'To',
                      border: InputBorder.none,
                      filled: false,
                      prefixIcon: Icon(
                        Icons.arrow_drop_down,
                        color: Colors.blue,
                        size: 28.0,
                      ),
                      suffixIcon: IconButton(
                          icon: Icon(Icons.arrow_drop_down,size: 28),
                          onPressed: () {
                            debugPrint('222');
                          })),
                ),
              )
        ]
              )
        ),
      )
      );
  }
}

我看到您使用 Padding 作为您的 body 来返回 Scaffold。尝试将其替换为 CenterContainer

关于input - Flutter输入装饰后缀图标不出现但一直显示十字符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55026054/

有关input - Flutter输入装饰后缀图标不出现但一直显示十字符号的更多相关文章

  1. ruby - 使用 rbenv 和 ruby​​-build 构建 ruby​​ 失败,出现 undefined symbol : SSLv2_method - 2

    我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby​​2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby​​-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm

  2. ruby - 鸭子输入字符串、符号和数组的优雅方式? - 2

    这是针对我无法破坏的现有公共(public)API,但我确实希望对其进行扩展。目前,该方法采用字符串或符号或任何其他在作为第一个参数传递给send时有意义的内容我想添加发送字符串、符号等列表的功能。我可以只使用is_a吗?数组,但还有其他发送列表的方法,这不是很像ruby​​。我将调用列表中的map,所以第一个倾向是使用respond_to?:map。但是字符串也会响应:map,所以这行不通。 最佳答案 如何将它们全部视为数组?String的行为与仅包含String的Array相同:deffoo(obj,arg)[*arg].eac

  3. ruby - 为什么 return 关键字会导致我的 'if block' 出现问题? - 2

    下面的代码工作正常:person={:a=>:A,:b=>:B,:c=>:C}berson={:a=>:A1,:b=>:B1,:c=>:C1}kerson=person.merge(berson)do|key,oldv,newv|ifkey==:aoldvelsifkey==:bnewvelsekeyendendputskerson.inspect但是如果我在“ifblock”中添加return,我会得到一个错误:person={:a=>:A,:b=>:B,:c=>:C}berson={:a=>:A1,:b=>:B1,:c=>:C1}kerson=person.merge(berson

  4. ruby - ruby 中的同一个程序如何接受来自用户的输入以及命令行参数 - 2

    我的ruby​​脚本从命令行参数获取某些输入。它检查是否缺少任何命令行参数,然后提示用户输入。但是我无法使用gets从用户那里获得输入。示例代码:test.rbname=""ARGV.eachdo|a|ifa.include?('-n')name=aputs"Argument:#{a}"endendifname==""puts"entername:"name=getsputsnameend运行脚本:rubytest.rbraghav-k错误结果:test.rb:6:in`gets':Nosuchfileordirectory-raghav-k(Errno::ENOENT)fromtes

  5. ruby-on-rails - 为什么用户必须输入 7 位数的 Twitter PIN 才能授予我的应用程序访问权限? - 2

    我正在为我的用户实现一些ruby​​onrails代码推特内容。我正在创建正确的oauth链接...类似http://twitter.com/oauth/authorize?oauth_token=y2RkuftYAEkbEuIF7zKMuzWN30O2XxM8U9j0egtzKv但在我的测试帐户授予对twitter的访问权限后,它会弹出一个页面,上面写着“您已成功授予对.我不知道用户应该在哪里输入此PIN以及他们为什么必须这样做。我认为这不是必要的步骤。Twitter应该将用户重定向到我在应用程序设置中提供的回调URL。有谁知道为什么会这样?更新我找到了thisarticle声明我需

  6. ruby - Formtastic,拥有 :as input type - 2

    如何将自己的字段类型添加到formtastic中?例如,我需要一个自定义的日期时间输入,我想要这样的东西::my_date%>这显然是行不通的,因为formtastic不知道:my_date(只有:boolean、:string、:datetime等等...)但是我怎样才能添加额外的输入类型呢? 最佳答案 您需要添加自定义输入法:classMyCustomFormtasticFormBuilder这非常适合新的HTML5输入类型。你可以这样使用它:MyCustomFormtasticFormBuilderdo|f|%>:my_dat

  7. css - Rails 4.1 和 Bootstrap 3 字形图标不工作 - 2

    我正在尝试消除使用Bootstrap3的Rails4元素中的glyphicon错误。我没有使用任何Bootstrapgem将其添加到Assets管道中。我手动将bootstrap.css和bootstrap.js添加到各自的app/assets目录下,分别添加到application.css和application.js什么的我现在在网络浏览器的控制台中看到以下内容:GEThttp://localhost:3000/fonts/glyphicons-halflings-regular.woff404(NotFound)localhost/:1GEThttp://localhost:30

  8. ruby - 安装 tiny_tds 在 mac os 10.10.5 上出现错误 - 2

    我正在使用macos,我想使用ruby​​驱动程序连接到sqlserver。我想使用tiny_tds,但它给出了缺少free_tds的错误,但它已经安装了。怎么能过这个?~brewinstallfreetdsWarning:freetds-0.91.112alreadyinstalled~sudogeminstalltiny_tdsBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtiny_tds:ERROR:Failedtobuildgemnativeextension.完整日志如下:/System

  9. ruby - 如何让几条 haml 线出现在同一行上? - 2

    我有以下haml:9%strongAskedby:10=link_to@user.full_name,user_path(@user)11.small="(#{@question.created_at.strftime("%B%d,%Y")})"这当前将链接和日期放在不同的行上,当它看起来像“链接(日期)”并且日期的类跨度为小...... 最佳答案 您的代码将生成类似这样的html:Askedby:UsernameApril26,2011当您使用类似.small的东西(即使用点而不指定元素类型)时,haml会创建一个implicit

  10. ruby - 获取数组中值的最大连续出现次数 - 2

    下面有没有更优雅的方法来实现这个:输入:array=[1,1,1,0,0,1,1,1,1,0]输出:4我的算法:streak=0max_streak=0arr.eachdo|n|ifn==1streak+=1elsemax_streak=streakifstreak>max_streakstreak=0endendputsmax_streak 最佳答案 类似于w0lf'sanswer,但通过从chunk返回nil来跳过元素:array.chunk{|x|x==1||nil}.map{|_,x|x.size}.max

随机推荐