My Flutter source code has these lines to control how users updating their profile:
class _TwoButtonWidget extends StatelessWidget {
const _TwoButtonWidget({
required this.userProvider,
required this.userNameController,
required this.emailController,
required this.phoneController,
required this.aboutMeController,
required this.addressController,
required this.cityController,
});
final TextEditingController userNameController;
final TextEditingController emailController;
final TextEditingController phoneController;
final TextEditingController aboutMeController;
final TextEditingController addressController;
final TextEditingController cityController;
final UserProvider userProvider;
Look at "cityController": Users have to put information to a required field named City.
Now I don't want City field is a required field so users could leave it blank.
So what have I to do next? Can you share me some lines to change this attribute?
Thank you very much!
CodePudding user response:
You can make nullable
final TextEditingController? cityController;
Now you can remove required
class _TowButtonWidget extends StatelessWidget {
const _TowButtonWidget({
Key? key,
required this.userNameController,
required this.emailController,
required this.phoneController,
required this.aboutMeController,
required this.addressController,
this.cityController,
required this.userProvider,
}) : super(key: key);
final TextEditingController userNameController;
final TextEditingController emailController;
final TextEditingController phoneController;
final TextEditingController aboutMeController;
final TextEditingController addressController;
final TextEditingController? cityController;
final UserProvider userProvider;
More about null-safety
CodePudding user response:
Remove the required key word and make city controller nullable by adding question mark. final TextEditingController? cityController;