我在第1页上有这个StreamBuilder
:
Widget _myFirebaseUser(BuildContext context) {
return StreamBuilder<FirebaseUser>(
stream: FirebaseAuth.instance.onAuthStateChanged,
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.connectionState == ConnectionState.active) {
print('-loading user2-');
FirebaseUser user = snapshot.data;
if (user == null) {
return Text('not logged in');
}
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(
user.photoUrl,
),
),
title: Text(user.displayName),
subtitle: Text(user.email),
trailing: new IconButton(
icon: new Icon(Icons.exit_to_app),
highlightColor: Colors.pink,
onPressed: () {
Navigator.of(context).pushNamed('/my-set');
}),
);
}
return Text("loading");
},
);
}
在Page2上我有这个:
TextField(
controller: inputNewElement,
decoration: InputDecoration(labelText: "Add Elements"),
onSubmitted: (elem) {
print("Changed textfield");
},
),
当我移至Page2并编辑TextField时,可以看到上一页的日志。我试过StreamBuilder
和FutureBuilder
的结果相同。
如何避免这种行为?