我的文本区域在颤振应用程序中没有显示

时间:2021-06-12 11:15:03

标签: flutter flutter-layout

嗨,我正在学习 Flutter 和编程新手我有一个问题,每当我在应用程序文本字段中写入时,我只有 2 个值,因为在文本字段中写入没有更多值并得到这个

<块引用>

更改撰写区域内的内容可能会导致 输入法表现怪异,因此不鼓励。看 https://github.com/flutter/flutter/issues/78827 了解更多详情 W/ListenableEditingState(9055): 一个监听器被添加到 EditingState W/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 不活动的 InputConnection W/IInputConnectionWrapper(9055): beginBatchEdit 在非活动 InputConnection W/IInputConnectionWrapper( 9055): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(9055):非活动状态下的endBatchEdit 输入连接

1 个答案:

答案 0 :(得分:0)

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

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

`