一切正常,除了现在我注意到Navigator.push中的Buildcontext出现粉红色,并且导航器推不起作用。所有其他页面中的buildcontext都可以正常工作。是什么原因导致的,只有两页?
Navigator.push(context/*this context appears in pink color*/
, MaterialPageRoute(builder: (context) => CreateAccount()));
这是用于创建帐户导航页面的主页。
createUserInFirestore() async {
// 1) check if user exists in users collection in database (according to their id)
final GoogleSignInAccount user = googleSignIn.currentUser;
DocumentSnapshot doc = await usersRef.document(user.id).get();
// 2) if the user doesn't exist, then we want to take them to the create account page
if (!doc.exists) {
final username = await Navigator.push(context , MaterialPageRoute(builder: (context) => CreateAccount()));
// 3) get username from create account, use it to make new user document in users collection
usersRef.document(user.id).setData({
"id": user.id,
"username": username,
"photoUrl": user.photoUrl,
"email": user.email,
"displayName": user.displayName,
"bio": "",
"timestamp": timestamp
});
// make new user their own follower (to include their posts in their timeline)
await followersRef
.document(user.id)
.collection('userFollowers')
.document(user.id)
.setData({});
doc = await usersRef.document(user.id).get();
}
currentUser = User.fromDocument(doc);
}
@override
void dispose() {
pageController.dispose();
super.dispose();
}
login() {
googleSignIn.signIn();
}
logout() {
googleSignIn.signOut();
}
onPageChanged(int pageIndex) {
setState(() {
this.pageIndex = pageIndex;
});
}
onTap(int pageIndex) {
pageController.animateToPage(
pageIndex,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
);
}
Scaffold buildAuthScreen() {
return Scaffold(
key: _scaffoldKey,
body: PageView(
children: <Widget>[
Timeline(currentUser: currentUser),
Shop(),
Designer(),
Live(),
ActivityFeed(),
],
controller: pageController,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics(),
),
bottomNavigationBar: CurvedNavigationBar(
onTap: onTap,
color: kSecondaryColor,
buttonBackgroundColor: Colors.transparent,
backgroundColor:Colors.black38,
animationCurve: Curves.elasticInOut,
animationDuration: Duration(milliseconds: 000),
height: 50.0,
items: <Widget>[
Icon(Icons.weekend, size: 30, color: kIcon,),
Icon(Icons.store, size: 30,color: kIcon,),
Icon(FontAwesomeIcons.swatchbook, size: 30,color: kIcon,),
Icon(Icons.play_arrow, size: 30,color: kIcon,),
Icon(Icons.inbox, size: 30,color: kIcon,),
],
),
);
}
Scaffold buildUnAuthScreen() {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors:[ kPrimaryColor,
kSecondaryColor
],
),
) ,
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text('FASHOW',
style: TextStyle(
fontFamily: "MajorMonoDisplay",
fontSize: 90.0,
color: Colors.white,),
),
InkWell(
onTap: login,
highlightColor: Colors.deepPurple,
splashColor: Colors.deepPurple,
child: Container(
width: 260.0,
height: 60.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/img/google.png'),
fit: BoxFit.cover,
)
),
),
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return isAuth? buildAuthScreen() : buildUnAuthScreen();
这是创建帐户页面,所有上下文均显示为粉红色。
class _CreateAccountState extends State<CreateAccount> {
final _scaffoldKey = GlobalKey<ScaffoldState>();
final _formKey = GlobalKey<FormState>();
String username;
submit() {
final form = _formKey.currentState;
if (form.validate()) {
form.save();
SnackBar snackbar = SnackBar(
content: Text("Welcome $username!"),
);
_scaffoldKey.currentState.showSnackBar(snackbar);
Timer(Duration(seconds: 2), () {
Navigator.pop(context, username);
});
}
}
@override
Widget build(BuildContext parentContext) {
return Scaffold(
key: _scaffoldKey,
appBar: header(context,
titleText: "Set up your profile", removeBackButton: true),
body: ListView(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 25.0),
child: Center(
child: Text(
"Create a username",
style: TextStyle(fontSize: 25.0),
),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: Container(
child: Form(
key: _formKey,
autovalidate: true,
child: TextFormField(
validator: (val) {
if (val.trim().length < 3 || val.isEmpty) {
return "Username too short";
} else if (val.trim().length > 12) {
return "Username too long";
} else {
return null;
}
},
onSaved: (val) => username = val,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Username",
labelStyle: TextStyle(fontSize: 15.0),
hintText: "Must be at least 3 characters",
),
)),
),
),
GestureDetector(
onTap: submit,
child: Container(
height: 50.0,
width: 350.0,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(7.0),
),
child: Center(
child: Text(
"Submit",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold),