微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 TextFormField Flutter 中加载 svg

如何解决在 TextFormField Flutter 中加载 svg

我想在 Flutter 中的 TextFormField 中加载 SVG 图像。我使用了 this SVG 加载库。但是每次 svg 图像显示在中心并且 TextFormField 的提示文本没有显示时。我想在 TextFormField 的末尾加载 SVG。 这是我的代码

Form(
                    key: _formKey,child: Column(
                      children: [
                        new RectWithBorder(AppColors.white,AppColors.gray,1.0,BorderRadius.circular(6.0),new EdgeInsets.all(0.0),new Padding(
                            padding: new EdgeInsets.all(10.0),child: TextFormField(
                                decoration: Inputdecoration(
                                  border: InputBorder.none,hintText: Strings.emailOrMobileText,),keyboardType: TextInputType.text,controller: emailController,validator: Utils.isValidEmailOrMobile,onSaved: (String value){
                                  this.email = value;
                                },))),new RectWithBorder(AppColors.white,new EdgeInsets.fromLTRB(0,10.0,0),child: TextFormField(
                            decoration: Inputdecoration(
                              border: InputBorder.none,hintText: Strings.passwordText,suffixIcon: new Padding(
                                padding: const EdgeInsets.all(5.0),child: new SizedBox(
                                  height: 20,child: SvgPicture.asset("assets/images/invisible.svg"),obscureText: true,validator: _validatePassword,onSaved: (String value){
                              this.password = value;
                            },)
                        ),new RoundedButton(
                          title: Strings.loginButtonText.toupperCase(),backgroundColor: AppColors.accent,radius: 6.0,textStyle: new TextStyle(fontSize: 18.0,fontWeight: FontWeight.bold,color: AppColors.white),textColor: AppColors.white,margin: new EdgeInsets.fromLTRB(0,20,onpressed: (){
                          Utils.isConnectedToInternet().then((isConnected){
                            if(isConnected == null || !isConnected){
                              Utils.showSnackBar(context,Strings.noInternetConnection);
                            } else{
                              // _verifyCaptcha();
                              _executeLogin(email,password);
                            }
                          });
                        },new Container(
                            margin: new EdgeInsets.fromLTRB(0,30.0,child: new GestureDetector(
                              child: Text(
                                Strings.forgotPasswordText,style: new TextStyle(
                                    color: AppColors.primary,fontSize: 15.0
                                ),))
                      ],

但它显示SVG如下图

有什么问题吗?

enter image description here

解决方法

从这里替换您的装饰代码。

decoration: InputDecoration(
              hintText: "Password",isDense: true,suffixIconConstraints: BoxConstraints(
                  minWidth: 2,minHeight: 2,),suffixIcon: InkWell(
                    child: new Padding(
                      padding: const EdgeInsets.all(5.0),child: new SizedBox(
                        height: 20,child: 
                        SvgPicture.asset("assets/images/invisible.svg"),onTap: () {}))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。