这是我的所有代码示例。如何在用户按下注册按钮时添加圆形进度指示器?
class CreateAccountScreen extends StatefulWidget {
@override
_CreateAccountScreenState createState() => _CreateAccountScreenState();
}
class _CreateAccountScreenState extends State<CreateAccountScreen>
with SingleTickerProviderStateMixin {
Future<Profile> _profile;
ProgressDialog _progressDialog;
bool _isloading;
这是按钮单击功能:
_pressCreateAccountButton(){
print("User pressed \"CREATE ACCOUNT\" button");
print("Login: ${editControllerName.text}, E-mail: ${editControllerEmail.text}, "
"password1: ${editControllerPassword1.text}, password2: ${editControllerPassword2.text}");
// Navigator.pushNamedAndRemoveUntil(context, "/main", (r) => false);
// Navigator.push(context, MaterialPageRoute(builder: (context) => BuisnessType()));
// MaterialPageRoute(builder: (context) => BuisnessType());
if(editControllerName.text == null || editControllerEmail.text == null || editControllerPassword1.text == null || editControllerPassword2.text == null || editControllerContact.text == null){
Fluttertoast.showToast(
msg: "Please input the necessary field",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}else if(!editControllerEmail.text.contains("@") || !editControllerEmail.text.contains(".") || !editControllerEmail.text.contains("com")){
Fluttertoast.showToast(
msg: "Please input valid email address",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
}else{
_isloading = !_isloading;
_profile = getProfileData(editControllerName.text.toString(), editControllerEmail.text, editControllerPassword2.text,editControllerContact.text, 3);
}
}
这里是剩下的api调用函数:
Future<Profile> getProfileData(String name, String strEmail, String strPass,String strPhone, int type) async{
await AllApiCall.userRegistration(name, strEmail, strPass, strPhone, type).then((value) {
print(value.success.token);
setState(() {
_isloading = false;
});
Navigator.push(context, MaterialPageRoute(builder: (context) => BuisnessType()));
});
}
Rest 是那个页面的设计:
final editControllerName = TextEditingController();
final editControllerEmail = TextEditingController();
final editControllerPassword1 = TextEditingController();
final editControllerPassword2 = TextEditingController();
final editControllerContact = TextEditingController();
@override
void initState() {
super.initState();
_isloading = false;
}
@override
void dispose() {
editControllerName.dispose();
editControllerEmail.dispose();
editControllerPassword1.dispose();
editControllerPassword2.dispose();
editControllerContact.dispose();
super.dispose();
}
我已经添加了 _isloading
但它在我的情况下不起作用。有什么办法可以解决这个问题吗?
答案 0 :(得分:0)
您可以使用 loading_overlay
包。你可以在这里找到它:
https://pub.dev/packages/loading_overlay
您必须定义一个 bool isLoading
,并将其初始值设置为 false
。
像这样:bool isLoading = false;
。
然后导入 {{1 }} 通过在文件顶部写入loading_overlay
来打包。
现在,像这样用 import 'package:loading_overlay/loading_overlay.dart';
小部件包装所有小部件:
LoadingOverlay
现在当你需要开始一个加载过程时,你可以这样写:
LoadingOverlay(
progressIndicator: CircularProgressIndicator(),
isLoading: isLoading, // our previously defined variable
child: YourWidgets(),
)
并停止它写:setState(()=>isLoading=true);
如果您有任何问题,请告诉我。