我是Flutter的新手,我试图在BLoC类(doRegister方法)中进行验证后提出一个AlertDialog,但实际上我不知道如何显示Dialog,有人可以帮我一些提示吗。我被困在这里。
我是否必须始终在StreamBuilder中创建AlertDialog小部件?还是可以仅在需要时创建(在验证之后),以及如何为对话框传递消息?
class RegisterBloc implements BaseBloc {
BehaviorSubject<String> _emailSubject =
BehaviorSubject.seeded('');
BehaviorSubject<String> _userSubject = BehaviorSubject.seeded('');
BehaviorSubject<String> _phoneSubject =
BehaviorSubject.seeded('');
BehaviorSubject<bool> _termsSubject =
BehaviorSubject.seeded(false);
BehaviorSubject<bool> _isLoadingSubject =
BehaviorSubject.seeded(false);
// Streams and Sinks....
void doRegister() {
if (!_selectedCountrySubject.hasValue ||
_selectedCountrySubject.value.isEmpty ||
_emailSubject.value.isEmpty ||
_userSubject.value.isEmpty ||
_phoneSubject.value.isEmpty) {
print('Empty');
// HERE I wanna show the Alert Message.
}
// Test to present a Progress
updateLoading(!_isLoadingSubject.value);
print('End Register');
}
}
这是我的StatefulWidget状态类
@override
Widget build(BuildContext context) {
const _sizedBox = SizedBox(height: 12.0);
return Scaffold(
appBar: AppBar(
title: Text(
Translations.of(context).text('app_title'),
style: Theme.of(context).textTheme.display1,
),
),
body: Stack(
children: <Widget>[
Column(
children: <Widget>[
Expanded(
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.all(15.0),
children: <Widget>[
Column(
children: <Widget>[
_countryDropDown(context),
_sizedBox,
_emailTextField(context),
_sizedBox,
_userTextField(context),
_sizedBox,
_phoneTextField(context),
_sizedBox,
_companyCode(context),
_sizedBox,
_inviteCodeTextField(context),
_sizedBox,
_termsAndConditionsCheck(),
],
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: _bottomButtons(),
),
],
),
_loadingIndicator(),
],
),
}