Tri*_*ing 7 loading dart flutter flutter-layout
我正在制作一个带有颤振的应用程序,我想要一个加载屏幕,同时从 Firestore 中获取数据我曾经在 android 中执行此操作 setvisibilty。似乎没有完全帮助
如果firebaseUser不是null,我想显示加载屏幕,这是我的initState方法
void initState() {
super.initState();
isRegistered();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.all(32),
child: Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Login"),
SizedBox(
height: 16,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
width: 50,
child: TextFormField(
maxLength: 4,
keyboardType: TextInputType.number,
controller: countryCodeController,
decoration: InputDecoration(
hintText: '+251',
),
),
),
Container(
width: 200,
child: TextFormField(
maxLength: 9,
keyboardType: TextInputType.number,
controller: phonenumberController,
decoration: InputDecoration(
hintText: '912345678',
),
),
),
],
),
SizedBox(
height: 16,
),
Container(
width: double.infinity,
child: FlatButton(
child: Text('Login'),
color: Colors.white,
padding: EdgeInsets.all(16),
onPressed: () {
final phoneNumber = countryCodeController.text.trim() + phonenumberController.text.trim();
if(phonenumberController.text.trim().length == 9 || countryCodeController.text.trim().length == 4){
loginUser(phoneNumber, context);
}else{
Fluttertoast.showToast(msg: "wronge input");
}
}),
)
],
),
),
),
);
}
void isRegistered() async{
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final FirebaseUser firebaseUser = await firebaseAuth.currentUser();
final snapShot = await Firestore.instance.collection("users").document(
firebaseUser.uid).get();
if (firebaseUser != null) {
if (snapShot.exists) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomePage(
firebaseUser: firebaseUser,
)));
}else{
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需查看我为您创建的这个示例:
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isLoading = false; // This is initially false where no loading state
List<Timings> timingsList = List();
@override
void initState() {
super.initState();
dataLoadFunction(); // this function gets called
}
dataLoadFunction() async {
setState(() {
_isLoading = true; // your loader has started to load
});
// fetch you data over here
setState(() {
_isLoading = false; // your loder will stop to finish after the data fetch
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: _isLoading
? CircularProgressIndicator() // this will show when loading is true
: Text('You widget tree after loading ...') // this will show when loading is false
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
让我知道它是否有效
| 归档时间: |
|
| 查看次数: |
1404 次 |
| 最近记录: |