1

import 'package:flutter/material.dart';
import 'package:time_trackerpractice/common_widgets/form_submit_button.dart';
import 'package:time_trackerpractice/services/auth.dart';

enum EmailSignInFormType{signIn,register}

class EmailSignInForm extends StatefulWidget {
  EmailSignInForm({@required this.auth});
  final AuthBase auth;


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

class _EmailSignInFormState extends State<EmailSignInForm> {

 final TextEditingController _emailController = TextEditingController();
 final TextEditingController _passwordController =TextEditingController();

 String get _email=>_emailController.text;
 String get _password=> _passwordController.text;

 EmailSignInFormType _formType = EmailSignInFormType.signIn;

 void _submit() async {
   try {
     if (_formType == EmailSignInFormType.signIn) {
       await widget.auth.signInWithEmailAndPassword(_email, _password);
     } else {
       await widget.auth.signInWithEmailAndPassword(_email, _password);
     }
   } catch (e) {
     print(e.toString());
   }
   Navigator.of(context).pop();
 }

  void _toggleFormType(){
   setState(() {
    _formType = _formType == EmailSignInFormType.signIn?
        EmailSignInFormType.register: EmailSignInFormType.signIn;
   });
  }

  List<Widget> _buildChildren() {
    final primaryText = _formType == EmailSignInFormType.signIn ? 'Sign in' : 'Create account';
    final secondaryText = _formType == EmailSignInFormType.signIn
        ? 'Need an account? Register'
        : 'Have an account? Sign in';
    return [
      TextField(
        controller: _emailController,
        decoration: InputDecoration(
          labelText: 'Email',
          hintText: 'test@test.com',
        ),
        autocorrect: false,
        keyboardType: TextInputType.emailAddress,
        textInputAction: TextInputAction.next,
      ),
      SizedBox(height: 8.0),
      TextField(
        controller: _passwordController,
        decoration: InputDecoration(
          labelText: 'Password',
        ),
        obscureText: true,
        textInputAction: TextInputAction.done,
      ),
      SizedBox(height: 8.0),
      FormSubmitButton(
        text: primaryText,
        onPressed: _submit,
      ),
      SizedBox(height: 8.0),
    FlatButton(
      child: Text(secondaryText),
      onPressed: _toggleFormType,
    ),
   ];

 }





  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment:CrossAxisAlignment.stretch,
        mainAxisSize: MainAxisSize.min,
        children: _buildChildren(),
      ),
    );
  }
}

enter image description here

I'm working on customizing my text field for my email and password.When I go to extract the method from emailController and passwordController.I receive an error saying "the end of the selection contains characters that do not belong to the statement.I checked everything and the code seems correct to me but its still not working can you please help me out.I imported the all of the code into a code snippet so that you could see all of the code on the page.

enter image description here

1 Answers1

1

I don't know if it's that, but you do have some random + in the end of line 47

Secondly, I assume you wanted to return Column with TextFields and other widgets in it, but instead there's bunch of widgets separated with commas.

So possibly you've lost the top part of your code