Flutter Error : getSelectedText on inactive InputConnection . getting while taking input

Viewed 105

error image:

only encounter error when doing custom email sign in. Textcontroller are used for the text field. above code is from Udemy flutter app development course Used Notifier state management technique

error details: W/IInputConnectionWrapper( 5518): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper( 5518): getSelectedText on inactive InputConnection W/IInputConnectionWrapper( 5518): getTextAfterCursor on inactive InputConnection W/IInputConnectionWrapper( 5518): beginBatchEdit on inactive InputConnection W/IInputConnectionWrapper( 5518): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper( 5518): endBatchEdit on inactive InputConnection

codE:

import 'package:first_one/app/sighn_in/emailsigninbloc.dart';
import 'package:first_one/app/sighn_in/validator.dart';
import 'package:first_one/services/auth.dart';
import 'package:first_one/services/auth_Provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'email_signin_change_model.dart';
import 'email_signin_model.dart';
import 'form_submit_button.dart';

class EmailSignInFormChangeNotifier extends StatefulWidget {
  // EmailSignInForm({required this.auth});
  // final AuthBase auth;
  EmailSignInFormChangeNotifier({Key? key, required this.model})
      : super(key: key);
  final EmailSignInChangeModel model;
  static Widget create(BuildContext context) {
    final auth = Provider.of<AuthBase>(context, listen: false);
    return ChangeNotifierProvider<EmailSignInChangeModel>(
      create: (_) => EmailSignInChangeModel(auth: auth),
      child: Consumer<EmailSignInChangeModel>(
        builder: (_, model, __) => EmailSignInFormChangeNotifier(
          model: model,
        ),
      ),
      // dispose: (_, bloc) => bloc.dispose(),
    );
  }

  @override
  _EmailSignInFormChangeNotifierState createState() =>
      _EmailSignInFormChangeNotifierState();
}

class _EmailSignInFormChangeNotifierState
    extends State<EmailSignInFormChangeNotifier> {
  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _PasswordController = TextEditingController();
  final FocusNode _emailFocusNode = FocusNode();
  final FocusNode _passwordFocusNode = FocusNode();

  String? email;

  String get _email => _emailController.text;
  String get _Password => _PasswordController.text;

  EmailSignInChangeModel get model => widget.model;
  @override
  void dispose() {
    print('dispose called');
    super.dispose();
  }

  Future<void> _submit() async {
    //to do print email and password
    print('submit called');

    print(
        ' email: ${_emailController.text} password: ${_PasswordController.text}');
    try {
      await model.submit();
    } catch (e) {
      print(e.toString());
      print('in e');
      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text('sign in failed'),
            content: Text(e.toString()),
            actions: [TextButton(onPressed: () {}, child: Text('OK'))],
          );
        },
      );
    }

    Navigator.of(context).pop();
  }

  void _emailEditingComplete() {
    print('email EDITING COMPLETE ');
    final newFocus = model.emailValidator.isValid(_email)
        ? _passwordFocusNode
        : _emailFocusNode;
    FocusScope.of(context).requestFocus(newFocus);
  }

  void _toggleFormType() {
    widget.model.toggleFormType();

    _emailController.clear();
    _PasswordController.clear();
  }

  emailSignInFormtype _formtype = emailSignInFormtype.signIn; //default enum
  List<Widget> _buildChildren() {
    return [
      // ignore: prefer_const_constructors
      _buildEmailTextField(),
      SizedBox(
        height: 8.0,
      ),
      // ignore: prefer_const_constructors
      _buildPasswordTextField(),
      SizedBox(
        height: 8.0,
      ),

      FormSubmitButton(
        text: model.primaryButtonText,
        onPressed: () => model.canSubmit ? _submit() : null,
      ),
      SizedBox(
        height: 8.0,
      ),

      FlatButton(
          onPressed: !model.isloading ? () => _toggleFormType() : null,
          child: Text(model.secondaryButtonText)),
    ];
  }

  TextField _buildPasswordTextField() {
    return TextField(
      controller: _PasswordController,
      focusNode: _passwordFocusNode,
      decoration: InputDecoration(
        labelText: 'password',
        errorText: model.passwordErrorText,
        enabled: model.isloading == false,
      ),
      textInputAction: TextInputAction.done,
      obscureText: true,
      onChanged: widget.model.updatePassword,
      onEditingComplete: () => _submit,
    );
  }

  TextField _buildEmailTextField() {
    bool ShowErrortext =
        model.submitted && !model.emailValidator.isValid(_email);
    return TextField(
      // ignore: prefer_const_constructors
      controller: _emailController,
      focusNode: _emailFocusNode,
      decoration: InputDecoration(
        labelText: 'Email',
        hintText: 'test@test.com',
        errorText: ShowErrortext ? model.EmailInvalidValidatorText : null,
        enabled: model.isloading == false,
      ),
      keyboardType: TextInputType.emailAddress,
      textInputAction: TextInputAction.next,
      // ignore: avoid_print
      onChanged: widget.model.updateEmail,
      onEditingComplete: () => _emailEditingComplete(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        mainAxisSize:
            MainAxisSize.min, //how much space we should occupy on space
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: _buildChildren(),
      ),
    );
  }
}
0 Answers
Related