Repository navigation
Closed
Description
Future builder fires every time a TextInputField is touched
return new FutureBuilder<FirebaseUser>(future: _initAsync(),
builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return new Text('Press button to start');
case ConnectionState.waiting:
return new Text('Awaiting result...');
default:
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else
if(snapshot.data == null){
return new Login();
}else{
return new Home();
}
}
},In the login widget when the user taps into a texfield the future builder fires which does not have sense.
class _LoginState extends State<Login> {
//Auth
final localAuth = new LocalAuthentication();
final firebaseAuth = FirebaseAuth.instance;
//SharePreferences
final String userSharePreference = "User";
final String passwordSharePreference = "Password";
//Log in
String user;
String password;
_logIn() async {
firebaseAuth.signInWithEmailAndPassword(email: user, password: password)
.then((FirebaseUser user){
Navigator.of(context).push(new MaterialPageRoute<Null>(builder: (BuildContext context) {
return new Home();
}));
})
.catchError((e){
Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(e.toString())));
});
}
_logInFingerprint() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
await localAuth.authenticateWithBiometrics(localizedReason: "FINGERPRINT")
.then((bool result){
setState((){
user = prefs.getString(userSharePreference);
password = prefs.getString(passwordSharePreference);
});
firebaseAuth.signInWithEmailAndPassword(email: user, password: password)
.then((FirebaseUser user){
Navigator.of(context).push(
new MaterialPageRoute<Null>(builder: (BuildContext context) {
return new Home();
}));
})
.catchError((e){
Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(e.toString())));
});
}).catchError((e){
Scaffold.of(context).showSnackBar(new SnackBar(content: new Text(e.toString())));
});
}
_showPassword() {}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
color: Colors.indigo,
child: new Center(
child: new Padding(
padding: new EdgeInsets.all(10.0),
child: new Card(
child: new Padding(
padding:
new EdgeInsets.fromLTRB(15.0, 10.0, 15.0, 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new FlutterLogo(
size: 100.0,
),
new TextFormField(
decoration: new InputDecoration(
hintText: "Insert user",
labelText: "User",
helperText: "Insert a valid user",
),
),
new TextFormField(
decoration: new InputDecoration(
hintText: "Insert Password",
labelText: "Password",
helperText: "Insert a valid Password"),
obscureText: true,
),
new ButtonTheme.bar(
// make buttons use the appropriate styles for cards
child: new ButtonBar(
children: <Widget>[
new FlatButton(
child: const Text('FINGERPRINT'),
onPressed: _logInFingerprint,
color: Colors.teal,
textColor: Colors.white,
),
new FlatButton(
child: const Text('LOG IN'),
onPressed: _logIn,
color: Colors.blue,
textColor: Colors.white,
),
],
),
),
],
),
),
)))));
}
}```Metadata
Metadata
Assignees
Labels
No labels
Activity
Hixie commentedon May 18, 2018
I don't understand the sample code above nor the issue being filed here (e.g. how do these code snippets relate?). Can you elaborate?
cfkloss commentedon Jun 10, 2018
It seems related to #11426
zoechi commentedon Aug 26, 2018
Closing as dup of #11426
Thanks @cfkloss
github-actions commentedon Sep 2, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.