'_Type'类型不是'String'类型的子类型

时间:2020-04-22 05:09:10

标签: flutter

class EditProfilePage extends StatefulWidget {
 final String currentOnlineUserId;

 EditProfilePage({
   this.currentOnlineUserId
 });

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

class _EditProfilePageState extends State<EditProfilePage> {
   TextEditingController profileNameTextEditingController = TextEditingController();
   TextEditingController bioTextEditingController = TextEditingController();
  final _scaffoldGlobalKey = GlobalKey<ScaffoldState>();
  bool loading = false;
  User user;
  bool  _bioValid = true;
  bool _profileNameValid = true;

@override
  void initState() {
    super.initState();
    getAndDisplayUserInformation();
  }

  getAndDisplayUserInformation() async{
    setState(() {
      loading = true;
   });

   DocumentSnapshot documentSnapshot = await                usersReference.document(widget.currentOnlineUserId).get();
   user = User.fromDocument(documentSnapshot);

   profileNameTextEditingController.text = user.profileName;
   bioTextEditingController.text = user.bio;

   setState(() {
     loading = false;
   });
  }


  upDateUserData(){
    setState(() {
      profileNameTextEditingController.text.trim().length < 3 || profileNameTextEditingController.text.isEmpty ? _profileNameValid = false : _profileNameValid = true;

       bioTextEditingController.text.trim().length > 110 ?  _bioValid = false : _bioValid = true;
    });

    if(_bioValid && _profileNameValid){
      usersReference.document(widget.currentOnlineUserId).updateData({

        'profileName': profileNameTextEditingController.text,
         'bio': bioTextEditingController.text,

      });

      SnackBar successsnackBar = SnackBar(content: Text ('Profile has been updated'));
      _scaffoldGlobalKey.currentState.showSnackBar(successsnackBar);
    }
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldGlobalKey,
      appBar: AppBar(
        backgroundColor:Colors.black,
        iconTheme: IconThemeData(color: Colors.white),
        title: Text('Edit Profile',style: TextStyle(color:Colors.white),),
        actions: <Widget>[
          IconButton(icon: Icon(Icons.done,color: Colors.white, size: 30.0), onPressed:() => Navigator.pop(context),),
        ],
      ),
      body: loading ? circularProgress() : ListView(
        children:<Widget>[
          Container(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(top:15.0, bottom:7.0),
                  child: CircleAvatar(
                    radius: 52.0,
                    backgroundImage: CachedNetworkImageProvider(user.url),

                  ),
                  ),
                  Padding(
                    padding: EdgeInsets.all(16.0),
                    child: Column(children:<Widget>[createProfileNameTextFormField(), createBioTextFormField()],),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top:29.0, left:54.0,right:54.0),
                    child: RaisedButton(
                      onPressed: upDateUserData(),
                      child: Text(
                        'Update',
                        style: TextStyle(
                          color:Colors.black,fontSize:16.0,
                        ),
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top:10.0, left:54.0,right:54.0),
                    child: RaisedButton(
                    color: Colors.red,
                      onPressed: logoutUser,
                      child: Text(
                        'Logout',
                        style: TextStyle(
                          color:Colors.black,fontSize:16.0,
                        ),
                      ),
                    ),
                  ),

              ],
            ),
          )
        ],
      )
    );
  }

  logoutUser() async{
   await gSignIn.signOut();
   Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
  }

  Column createProfileNameTextFormField(){
  return Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    Padding(
      padding: EdgeInsets.only(top:13.0),
      child: Text(
        'Profile Name',style:TextStyle(color:Colors.grey),
      ),
      ),
      TextField(
        style:TextStyle(color: Colors.white),

        controller: profileNameTextEditingController,
        decoration: InputDecoration(
          hintText: 'write your profile name...',
          enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(color:Colors.grey),
          ),
          focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(color:Colors.white),
          ),
          hintStyle: TextStyle(color:Colors.grey),
          errorText: _profileNameValid ? Null : 'Profile name is very short',
        ),
      ),
  ],
  );
}

Column createBioTextFormField(){
  return Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: <Widget>[
    Padding(
      padding: EdgeInsets.only(top:13.0),
      child: Text(
        'Bio',style:TextStyle(color:Colors.grey),
      ),
      ),
      TextField(
        style:TextStyle(color: Colors.white),

        controller: bioTextEditingController,
        decoration: InputDecoration(
          hintText: 'write your Bio name...',
          enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(color:Colors.grey),
          ),
          focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(color:Colors.white),
          ),
          hintStyle: TextStyle(color:Colors.grey),
          errorText: _bioValid ? Null : 'Bio name is too long',
        ),
      ),
  ],
  );
}
}
I/flutter ( 6244): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 6244): The following assertion was thrown building EditProfilePage(dirty, state:
I/flutter ( 6244): _EditProfilePageState#7de7d):
I/flutter ( 6244): type '_Type' is not a subtype of type 'String'
I/flutter ( 6244): 
I/flutter ( 6244): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 6244): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 6244): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 6244):   https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 6244): 
I/flutter ( 6244): The relevant error-causing widget was:
I/flutter ( 6244):   EditProfilePage file:///C:/Start/lot/lib/pages/profilepage.dart:163:62
I/flutter ( 6244): 
I/flutter ( 6244): When the exception was thrown, this was the stack:
I/flutter ( 6244): #0      _EditProfilePageState.createProfileNameTextFormField (package:lot/pages/EditProfilePage.dart:169:40)
I/flutter ( 6244): #1      _EditProfilePageState.build (package:lot/pages/EditProfilePage.dart:105:53)
I/flutter ( 6244): #2      StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)
I/flutter ( 6244): #3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
I/flutter ( 6244): #4      Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter ( 6244): #5      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
I/flutter ( 6244): #6      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
I/flutter ( 6244): #7      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter ( 6244): #8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
I/flutter ( 6244): #9      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
I/flutter ( 6244): #10     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
I/flutter ( 6244): #14     _invoke (dart:ui/hooks.dart:259:10)
I/flutter ( 6244): #15     _drawFrame (dart:ui/hooks.dart:217:3)
I/flutter ( 6244): (elided 3 frames from package dart:async)
I/flutter ( 6244):
I/flutter ( 6244): ════════════════════════════════════════════════════════════════

0 个答案:

没有答案