Почему наблюдаемые не распознаются внутри функций сборки Observers во Flutter Mobx - PullRequest
0 голосов
/ 30 апреля 2020

Я пытаюсь установить два свойства TextFields (Email и пароль) внутри Обозревателя, используя observables.Properties, такие как obscure и onChanged. Но это дает мне следующую ошибку: В функции сборки Observer не обнаружены наблюдаемые объекты. Здесь ниже у вас есть мой код с Observers:

класс LoginScreen extends StatefulWidget {

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

class _LoginScreenState extends State<LoginScreen> {
  LoginStore loginStore = LoginStore();

// ... child: Padding (padding: const EdgeInsets.all (16), child : Столбец (mainAxisSize: MainAxisSize.min, дети: [CustomTextField (подсказка: «E-mail», префикс: Icon (Icons.account_circle), textInputType: TextInputType.emailAddress, onChanged: loginStore.setEmail, включено: true,), SizedBox (высота: 16,),

                    Observer(
                      builder: (_){
                        return   CustomTextField(
                          hint: 'Senha',
                          prefix: Icon(Icons.lock),
                          obscure: !loginStore.isPassVisible,
                          onChanged: loginStore.setPassword,
                          enabled: true,
                          suffix: CustomIconButton(
                            radius: 32,
                            iconData: loginStore.isPassVisible ?
                            Icons.visibility:
                            Icons.visibility_off,
                            onTap: loginStore.togglePassVisibility,
                          ),
                        );

                      },
                    ),

                    const SizedBox(height: 16,),
                    Observer(
                      builder: (_){
                        return SizedBox(
                          height: 44,
                          child: RaisedButton(
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(32),
                            ),
                            child: loginStore.isLoading ? CircularProgressIndicator() : 
                            Text('Login'),
                            color: Theme.of(context).primaryColor,
                            disabledColor: Theme.of(context).primaryColor.withAlpha(100),
                            textColor: Colors.white,
                            onPressed:(){

                              loginStore.login();
                            }


                            /*
                            loginStore.isFormValid ?(){


                             Navigator.of(context).pushReplacement(
                                  MaterialPageRoute(builder: (context)=>ListScreen())
                                // ignore: unnecessary_statements
                              ) ;
                            }: null*/

}

НИЖЕ КЛАСС МОЕГО МАГАЗИНА

part 'login_store.g.dart';

class LoginStore =_LoginStore with _$LoginStore;

abstract class _LoginStore with Store{

  _LoginStore(){
    autorun((_){
      print(isFormValid);

    });

  }
  @observable
  bool isLoading=false;


  @observable
  bool isPassVisible=false;

  @observable
  String _email="";

  @observable
  String _password="";

  @action
  void togglePassVisibility()=>isPassVisible = !isPassVisible;


  @action
  void setEmail(String value)=> _email=value;

  @action
  void setPassword(String value)=>_password =value;

  @action
  Future<void> login ()async {

    isLoading=true;

    await Future.delayed(Duration(seconds: 2));

    isLoading=false;

  }

  @computed
  bool get isFormValid => _email.length > 6 && _password.length > 6 && isLoading;






}
...