【发布时间】:2021-06-29 19:11:19
【问题描述】:
这是授权文件:
Future attempt(String token) async {
try {
Dio.Response response = await dio().get(
'/user',
options: Dio.Options(
headers: {'Authorization': 'Bearer $token'},
followRedirects: false,
validateStatus: (status) {
return status! < 500;
}),
);
'get user info '
_user = User.fromJson(json.decode(response.toString()));
_authenticated = true;
// return response;
} catch (e) {
_authenticated = false;
}
notifyListeners();
}
在这个 main.dart 文件中,我想使用一个 CircularProgressIndicator 小部件
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: NavDrawer(),
body: Center(child: Consumer<Auth>(
builder: (context, auth, child) {
if (auth.authenticated) {
return Text('You are logged in!');
} else {
return Text('You are not logged in!');
}
}
},
)),
);
}
}
【问题讨论】:
-
您可以显示带有圆形指示器的对话框,直到您收到请求的响应