我有一个页面,其中第一个是登录页面和基于bloc逻辑加载的逻辑按钮,如下所示。之所以将bloc放在登录页面上是因为我会检查是否生成了一个信号用户ID或不。仅当其生成后,登录按钮才会出现。
Widget build(BuildContext context) {
return BlocProviderTree(
blocProviders: [
BlocProvider<LoginBloc>(
bloc: loginBLoC,
),
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
body: _isLoading ? _loadingScreen() : _loginScreen(),
resizeToAvoidBottomPadding : false,
),
);
}
下面是完成登录按钮的逻辑。
children: <Widget>[
Expanded(
flex: 1,
child:Padding(
padding: EdgeInsets.only(left: 70.0, right: 70.0),
child:
BlocBuilder(
bloc: loginBLoC,
builder: (BuildContext context, LoginData state) {
print("Build login button login page "+state.toString());
if(state is LoginData){
if(state.userOneSingalID!=""){
localuserIDOneSignal = state.userOneSingalID;
return RaisedButton(
elevation: 5,
padding: const EdgeInsets.all(12),
textColor: Colors.white,
color: Colors.blue,
child: Text("LOGIN",style: new TextStyle(
fontFamily: "BPreplay",
fontSize: 13.0,
color: Colors.white,
fontWeight: FontWeight.w400
),),
//onPressed: () {},
onPressed: _authenticateUser,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0)
)
);
}
return Container(height: 0, width: 0,);
}
return Container(height: 0, width: 0,);
}
)
)
)
]
在登录按钮下面,然后是下一步,我有这个Flatbutton,它将带我进入下一页,如果用户没有任何帐户,则将转到此处进行注册。我在下面提供了它的代码。为此,我将它称为formUI函数,并在其中仅构建一个文本字段和一个下拉列表。
new Container(
alignment: Alignment.topCenter,
padding: new EdgeInsets.only(
top: MediaQuery.of(context).size.height * .83,
right: 50.0,
left: 50.0),
child: new FlatButton(
color: Colors.transparent,
child: Text("REGISTER",style: new TextStyle(
fontFamily: "BPreplay",
fontSize: 13.0,
color: Colors.grey,
fontWeight: FontWeight.w700
),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RegisterPage(
),
),
);
},
),
),
因此,如果用户按下“注册”按钮,则会将他带到下一页。在此页面中,我只是做一些测试。
Widget build(BuildContext context) {
return BlocProviderTree(
blocProviders: [
BlocProvider<ApiBloc>(
bloc: apiBLoC,
),
BlocProvider<TitleBloc>(
bloc: titleBLoC,
),
],
child: Scaffold(
backgroundColor: Colors.white,
key: _scaffoldKey,
body: SafeArea(
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 30.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Form(
key: _key,
//autovalidate: _validate,
child: formUI(),
),
],
)
)
)
)
);
}
下面是实际的formUI函数详细信息,它由一个下拉列表和一个文本字段组成。
Widget formUI() {
return new Column(
children: <Widget>[
BlocBuilder(
bloc: titleBLoC,
builder: (BuildContext context, TitleState state) {
print("Build title dropdown "+state.toString());
if(state is TitleInitialState){
return DropdownButtonFormField(
//hint: Text('Select County'),
onChanged: changedTitleDropDownItem,
items: _titledropDownMenuItems,
value: _currentTitle,
decoration: InputDecoration(
labelText: 'Title',
),
validator: validateDropDown,
);
}
else if(state is SetTitleSelectedState){
return DropdownButtonFormField(
//hint: Text('Select County'),
onChanged: changedTitleDropDownItem,
items: _titledropDownMenuItems,
value: state.selectedTitle,
decoration: InputDecoration(
labelText: 'Title',
),
validator: validateDropDown,
);
}
return Container(height: 0, width: 0,);
}
),
SizedBox(
height: 10.0,
),
TextFormField(
onChanged: (value) => firstName = value,
validator: validateName,
maxLength: 20,
decoration: InputDecoration(
labelText: 'First Name ',
//errorText: "Enter First Name",
),
),
我注意到和奇怪的问题如下。
I / flutter(31012):[pop old]未命名 I / flutter(31012):[至新路线]未命名 I / flutter(31012):“ SetTitleSelectedState”的构建标题下拉实例
如何避免所有这些事件和问题?
我已经进行了研究,并尝试了TextEditingController _searchController1的所有不同方式;然而,随着键盘的打开,所有乐团都被重新加载并再次更新。如何避免呢?