Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

bloc - Flutter Stream<String> values all null

I have created a registration page and using bloc to Stream data entered by user, every time I edit new text box the stream data on pervious goes to null.

There are 4 text fields and once i fill them all and call the onclick function that would print the data of all text boxes they all return a null value.

class MobRegistrationScreen extends StatefulWidget {
  MobRegistrationScreen({Key key}) : super(key: key);

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

class _MobRegistrationScreenState extends State<MobRegistrationScreen> {
  LoginPageBloc bloc;

  @override
  void dispose() {
    bloc.dispose();
    super.dispose();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    bloc = LoginBlocProvider.of(context);
  }

  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

  final _textBorder = OutlineInputBorder(
    borderRadius: BorderRadius.all(
      Radius.circular(15.0),
    ),
    borderSide: BorderSide(
      color: Colors.transparent,
    ),
  );
  final _textErrorBorder = OutlineInputBorder(
    borderRadius: BorderRadius.all(
      Radius.circular(15.0),
    ),
    borderSide: BorderSide(
      color: errorColor,
    ),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      resizeToAvoidBottomPadding: false,
      body: Container(
        height: deviceHeight,
        width: deviceWidth,
        color: primaryColor,
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
              child: Container(
                width: deviceWidth,
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      width: 100,
                      child: InkWell(
                        child: Icon(
                          Icons.arrow_back_rounded,
                          size: 55,
                          color: lightColor,
                        ),
                      ),
                    ),
                    Container(
                      width: deviceWidth - 240,
                      alignment: Alignment.center,
                      child: Image.asset(
                        'assets/images/logo.png',
                        height: 120,
                      ),
                    ),
                    Container(
                      width: 100,
                    ),
                  ],
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 10),
              child: Align(
                alignment: Alignment.centerLeft,
                child: Text(
                  'Let's set you up!',
                  style: Theme.of(context)
                      .textTheme
                      .headline3
                      .copyWith(color: lightColor, letterSpacing: 1.5),
                  textAlign: TextAlign.left,
                ),
              ),
            ),
            registrationForm(),
          ],
        ),
      ),
    );
  }

  Widget registrationForm() {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
      child: Container(
        height: deviceHeight - 270,
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(bottom: 10),
                child: StreamBuilder<String>(
                  stream: bloc.registerFullName,
                  builder: (context, snapshot) => TextFormField(
                    // controller: registrationFullNameController,
                    // focusNode: registrationFullNameFocusNode,
                    onChanged: bloc.registerFullNameChanged,
                    
                    autocorrect: false,
                    keyboardType: TextInputType.name,
                    textInputAction: TextInputAction.next,
                    obscureText: false,
                    textCapitalization: TextCapitalization.words,
                    style: Theme.of(context)
                        .textTheme
                        .bodyText1
                        .copyWith(letterSpacing: 1.5, color: lightColor),
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.all(25.0),
                      hintText: 'Full Name',
                      hintStyle: Theme.of(context)
                          .textTheme
                          .bodyText1
                          .copyWith(color: lightColor),
                      errorText: snapshot.error,
                      border: _textBorder,
                      enabledBorder: _textBorder,
                      focusedBorder: _textBorder,
                      disabledBorder: _textBorder,
                      errorBorder: _textErrorBorder,
                    ),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(bottom: 10),
                child: Row(
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(20),
                      ),
                      width: 100,
                      height: 50,
                      child: CountryCodePicker(
                        onChanged: bloc.registerPhoneCodeChanged,
                        initialSelection: '+971',
                        favorite: ['+971', '+91'],
                        showCountryOnly: false,
                        showOnlyCountryWhenClosed: true,
                        showDropDownButton: false,
                        alignLeft: false,
                        flagWidth: 80,
                        hideSearch: true,
                        showFlag: true,
                        showFlagDialog: true,
                        showFlagMain: true,
                        hideMainText: true,
                        boxDecoration: BoxDecoration(
                          color: lightColor,
                          borderRadius: BorderRadius.circular(25),
                        ),
                      ),
                    ),
                    Container(
                      width: deviceWidth - 150,
                      child: StreamBuilder<String>(
                        stream: bloc.registerPhone,
                        builder: (context, snapshot) => TextFormField(
                          // controller: registrationFullNameController,
                          // focusNode: registrationFullNameFocusNode,
                          onChanged: bloc.registerPhoneChanged,
                          // initialValue: '',
                          autocorrect: false,
                          keyboardType: TextInputType.phone,
                          textInputAction: TextInputAction.next,
                          obscureText: false,
                          textCapitalization: TextCapitalization.none,
                          style: Theme.of(context)
                              .textTheme
                              .bodyText1
                              .copyWith(letterSpacing: 1.5, color: lightColor),
                          decoration: InputDecoration(
                            contentPadding: const EdgeInsets.all(25.0),
                            hintText: 'Mobile Number',
                            hintStyle: Theme.of(context)
                                .textTheme
                                .bodyText1
                                .copyWith(color: lightColor),
                            errorText: snapshot.error,
                            border: _textBorder,
                            enabledBorder: _textBorder,
                            focusedBorder: _textBorder,
                            disabledBorder: _textBorder,
                            errorBorder: _textErrorBorder,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(bottom: 10),
                child: StreamBuilder<String>(
                  stream: bloc.registerEmail,
                  builder: (context, snapshot) => TextFormField(
                    // controller: registrationFullNameController,
                    // focusNode: registrationFullNameFocusNode,
                    onChanged: bloc.registerEmailChanged,
                    // initialValue: '',
                    autocorrect: false,
                    keyboardType: TextInputType.emailAddress,
                    textInputAction: TextInputAction.next,
                    obscureText: false,
                    textCapitalization: TextCapitalization.words,
                    style: Theme.of(context)
                        .textTheme
                        .bodyText1
                        .copyWith(letterSpacing: 1.5, color: lightColor),
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.all(25.0),
                      hintText: 'Email Address',
                      hintStyle: Theme.of(context)
                          .textTheme
                          .bodyText1
                          .copyWith(color: lightColor),
                      errorText: snapshot.error,
                      border: _textBorder,
                      enabledBorder: _textBorder,
                      focusedBorder: _textBorder,
                      disabledBorder: _textBorder,
                      errorBorder: _textErrorBorder,
                    ),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(bottom: 10),
                child: StreamBuilder<String>(
                  stream: bloc.registerPassword,
                  builder: (context, snapshot) => TextFormField(
                    // controller: registrationFullNameController,
                    // focusNode: registrationFullNameFocusNode,
                    onChanged: bloc.registerPasswordChanged,
                    // initialValue: '',
                    autocorrect: false,
                    keyboardType: TextInputType.visiblePassword,
                    textInputAction: TextInputAction.done,
                    obscureText: true,
                    textCapitalization: TextCapitalization.words,
                    style: Theme.of(context)
                        .textTheme
                        .bodyText1
                        .copyWith(letterSpacing: 1.5, color: lightColor),
                    decoration: InputDecoration(
                      contentPadding: const EdgeInsets.all(25.0),
                      hintText: 'Password',
                      hintStyle: Theme.of(context)
                          .textTheme
                          .bodyText1
                          .copyWith(color: lightColor),
                      errorText: snapshot.error,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...