将代码分解为方法参数(Dart + Flutter + GetX)
Break out code to method argument (Dart + Flutter + GetX)
如何将“myEditMyProfileController.initFullName”和“myEditMyProfileController.tempFullName”分解为方法参数,控制器是 GetxController 而 initFullName/tempFullName 是 String...? (我用的是GetX + Flutter + Dart)
Container buildEditProfileField(String myLabel, TextEditingController myTextEditingController )
{
return Container(
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: GetBuilder<EditMyProfileController>(
init: EditMyProfileController(),
builder: (value) => TextFormField(
controller: myTextEditingController,
decoration: InputDecoration(
labelText: myLabel,
border: OutlineInputBorder(),
suffixIcon: myEditMyProfileController.initFullName != myEditMyProfileController.tempFullName ? Icon(Icons.update, color: Colors.teal) : null,
),
),
),
),
);
}
成功解决问题...
GetBuilder 需要包含方法调用才能正确更新。
GetBuilder<EditMyProfileController>(
init: controller,
builder: (_) {
return ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
buildEditProfileField("Full name", controller.myFullNameController, controller.initFullName, controller.tempFullName),
],
);
}
),
TextFormField buildEditProfileField(String myLabel, TextEditingController myTextEditingController, String init, String temp)
{
return TextFormField(
controller: myTextEditingController,
decoration: InputDecoration(
labelText: myLabel,
border: OutlineInputBorder(),
suffixIcon: init != temp ? Icon(Icons.update, color: Colors.teal) : null,
),
);
}
如何将“myEditMyProfileController.initFullName”和“myEditMyProfileController.tempFullName”分解为方法参数,控制器是 GetxController 而 initFullName/tempFullName 是 String...? (我用的是GetX + Flutter + Dart)
Container buildEditProfileField(String myLabel, TextEditingController myTextEditingController )
{
return Container(
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: GetBuilder<EditMyProfileController>(
init: EditMyProfileController(),
builder: (value) => TextFormField(
controller: myTextEditingController,
decoration: InputDecoration(
labelText: myLabel,
border: OutlineInputBorder(),
suffixIcon: myEditMyProfileController.initFullName != myEditMyProfileController.tempFullName ? Icon(Icons.update, color: Colors.teal) : null,
),
),
),
),
);
}
成功解决问题...
GetBuilder 需要包含方法调用才能正确更新。
GetBuilder<EditMyProfileController>(
init: controller,
builder: (_) {
return ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
buildEditProfileField("Full name", controller.myFullNameController, controller.initFullName, controller.tempFullName),
],
);
}
),
TextFormField buildEditProfileField(String myLabel, TextEditingController myTextEditingController, String init, String temp)
{
return TextFormField(
controller: myTextEditingController,
decoration: InputDecoration(
labelText: myLabel,
border: OutlineInputBorder(),
suffixIcon: init != temp ? Icon(Icons.update, color: Colors.teal) : null,
),
);
}