【问题标题】:My Text area is nothing show in flutter app我的文本区域在颤振应用程序中没有显示
【发布时间】:2021-08-29 01:31:37
【问题描述】:

嗨,我正在学习颤振和编程新手

更改撰写区域内的内容可能会导致 输入法行为怪异,因此不鼓励。看 https://github.com/flutter/flutter/issues/78827了解更多详情 W/ListenableEditingState(9055): 一个监听器被添加到 EditingState 在使用 IInputConnectionWrapper(9055)进行批量编辑时: 非活动 InputConnection E/FlutterView(9055)上的 getSelectedText: dispatchKeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_A, scanCode=30, metaState=0, flags=0x8, repeatCount=0, eventTime=9164435, downTime=9164435, deviceId=0, source=0x101 }`

    import 'package:flutter/material.dart';
    import 'class_object.dart';
    import 'package:flash_chat/constants.dart';
    class RegistrationScreen extends StatefulWidget {
      static const String id = 'registration_Screen';
      @override
      _RegistrationScreenState createState() => _RegistrationScreenState();
    }

    class _RegistrationScreenState extends State<RegistrationScreen> {
      String email;
      String password;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.white,
          body: SingleChildScrollView(
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 24.0),
              child:  Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Hero(
                      tag: 'logo',
                      child: Container(
                        height: 200.0,
                        child: Image.asset('images/logo.png'),
                      ),
                    ),
                    SizedBox(
                      height: 48.0,
                    ),
                    TextFormField(
                      onChanged: (value) {
                        //Do something with the user input.
                        email = value;
                      },
                      decoration:  kTextFieldDecoration.copyWith(
                          hintText: 'Enter Your Password'
                      ),
                    ),
                    SizedBox(
                      height: 8.0,
                    ),
                    TextFormField(
                      onChanged: (value) {
                        //Do something with the user input.
                        password=value;

                      },
                      decoration: kTextFieldDecoration.copyWith(
                          hintText: 'Enter Your Email'
                      )
                    ),
                    SizedBox(
                      height: 24.0,
                    ),
                    RoundButton(
                      Lable: 'Register',
                      Colour: Colors.blue,
                      onPress: () {
                        print(email);
                        print(password);
                        // Go to the Registration Screen
                        Navigator.pushNamed(context, RegistrationScreen.id);
                      },
                    ),
                  ],
                ),
              ),
          ),
          );
      }
    }

W/IInputConnectionWrapper(9055):beginBatchEdit 处于非活动状态 InputConnection W/IInputConnectionWrapper(9055):getTextBeforeCursor 在非活动 InputConnection W/IInputConnectionWrapper(9055): 非活动 InputConnection 上的 getTextAfterCursor W/IInputConnectionWrapper(9055):getSelectedText 处于非活动状态 InputConnection W/IInputConnectionWrapper(9055):endBatchEdit on 带 IInputConnectionWrapper 的非活动 InputConnection(9055): beginBatchEdit 在非活动 InputConnection W/IInputConnectionWrapper( 9055): 非活动 InputConnection 上的 getTextBeforeCursor W/IInputConnectionWrapper(9055):endBatchEdit 处于非活动状态 输入连接

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    啊,一个简单的错误,你没有将文本编辑控制器传递给文本字段, 这是你完成的代码:-`

     import 'package:flutter/material.dart';
     import 'class_object.dart';
     import 'package:flash_chat/constants.dart';
    class RegistrationScreen extends StatefulWidget {
     static const String id = 'registration_Screen';
      @override
    _RegistrationScreenState createState() => _RegistrationScreenState();
    }
    
    class _RegistrationScreenState extends State<RegistrationScreen> {
    TextEditingController emailController;
    TextEditingController passwordController;
    String email;
    String password;
    
    @override
    void initState() {
    emailController = TextEditingController();
    passwordController = TextEditingController();
    super.initState(); }
    @override
    Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 24.0),
          child:  Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Hero(
                  tag: 'logo',
                  child: Container(
                    height: 200.0,
                    child: Image.asset('images/logo.png'),
                  ),
                ),
                SizedBox(
                  height: 48.0,
                ),
                TextFormField(
                controller:emailController,
                  onChanged: (value) {
                    //Do something with the user input.
                    email = value;
                  },
                  decoration:  kTextFieldDecoration.copyWith(
                      hintText: 'Enter Your Password'
                  ),
                ),
                SizedBox(
                  height: 8.0,
                ),
                TextFormField(
                  controller:phoneController
                  onChanged: (value) {
                    //Do something with the user input.
                    password=value;
    
                  },
                  decoration: kTextFieldDecoration.copyWith(
                      hintText: 'Enter Your Email'
                  )
                ),
                SizedBox(
                  height: 24.0,
                ),
                RoundButton(
                  Lable: 'Register',
                  Colour: Colors.blue,
                  onPress: () {
                    print(email);
                    print(password);
                    // Go to the Registration Screen
                    Navigator.pushNamed(context, RegistrationScreen.id);
                  },
                ),
              ],
            ),
          ),
      ),
      );
     }
    }
    

    `

    【讨论】:

    • 我遇到了同样的问题,我的文本控制器已传入。这种情况最近才开始发生......
    猜你喜欢
    • 2021-08-13
    • 2019-08-01
    • 1970-01-01
    • 2019-02-01
    • 2022-10-09
    • 1970-01-01
    • 2022-01-16
    • 2020-10-20
    • 2021-03-05
    相关资源
    最近更新 更多