首页 > 解决方案 > W/IInputConnectionWrapper(1768):非活动 InputConnection Flutter 上的 getSelectedText

问题描述

我正在学习颤振,并且遇到了这些错误,我尝试过搜索,但都是徒劳的。

错误:

W/IInputConnectionWrapper( 1768): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper( 1768): requestCursorAnchorInfo on inactive InputConnection
W/IInputConnectionWrapper( 1768): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper( 1768): getTextBeforeCursor on inactive InputConnection

问题:

当我单击文本字段时会发生这种情况,但它有一个转折点。当我第一次去这个小部件并选择文本字段来写电子邮件时,没有发生错误。但是当我移动到另一个活动或通过来回返回这个活动时,当我单击任何输入字段时,它会给出这些错误。

请帮忙。

代码:

import 'package:brew_crew/services/auth.dart';
import 'package:flutter/material.dart';

final _formKey = GlobalKey<FormState>();

class SignIn extends StatefulWidget {
  @override
  _SignInState createState() => _SignInState();
}

class _SignInState extends State<SignIn> {

  final AuthService _auth = AuthService();

  final emailController = TextEditingController();
  final passwordController = TextEditingController();

  @override
  void dispose()
  {
    emailController.dispose();
    passwordController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.brown[50],
      appBar: AppBar(title: Text('Sign In'), backgroundColor: Colors.brown),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal:50.0),
        child: Form(
          key: _formKey,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Brew Crew',
                style: TextStyle(
                  color: Colors.brown,
                  fontSize: 48.0,
                  fontWeight: FontWeight.w200,
                  letterSpacing: 5.0,
                ),
              ),
              Text(
                'The App',
                style: TextStyle(
                  color: Colors.brown,
                  fontSize: 18.0,
                  fontWeight: FontWeight.w700,
                  letterSpacing: 1.0,
                ),
              ),
              SizedBox(height:30.0),
              TextFormField(
                controller: emailController,
                decoration: InputDecoration(labelText: 'Your email address'),
                cursorColor: Colors.brown,
                validator: (value) { 
                  if(value.isEmpty)
                    return 'Email cannot be empty';
                  else if(!value.contains('@'))
                    return 'Email must contain @ symbol';
                  else
                    return null;
                },
              ),
              TextFormField(
                controller: passwordController,
                decoration: InputDecoration(labelText: 'Your password'),
                obscureText: true,
                validator: (value) { 
                  if(value.isEmpty)
                    return 'Password cannot be empty';
                  else if(value.length < 6)
                    return 'Password should be at least 6 characters';
                  else
                    return null;
                },
              ),
              SizedBox(height: 30.0,),
              RaisedButton.icon(
                onPressed: (){
                  if(_formKey.currentState.validate())
                  {
                    print('Email: ${emailController.text}');
                    print('Password: ${passwordController.text}');
                  }
                },
                color: Colors.brown,
                textColor: Colors.white,
                icon: Icon(Icons.input), 
                label: Text('Log In'),
              ),
              SizedBox(height: 20.0,),
              GestureDetector(      
                onTap: () {
                  Navigator.pushReplacement(context, 
                      MaterialPageRoute(builder: (context) => Register()));
                },
                child: Text(
                  'Not a user? Click here to register',
                  style: TextStyle(
                    color: Colors.brown,
                  ),
                )
              ),
              
            ],
          )
        ),
      ),  
    );
  }
}

标签: flutter

解决方案


推荐阅读