我是初学者,在显示文本后,在显示和隐藏颤动单选按钮选择上存在一些冲突,任何人都知道如何在select yes
时显示,然后显示remark text filed
>
这里是我的代码
class MyBookPage extends StatefulWidget {
final BookDetails _bookDetails;
MyBookPage(this._bookDetails);
@override
MyBookPageState createState() {
return MyBookPageState();
}
}
class MyBookPageState extends State<MyBookPage> {
final _formKey = GlobalKey<FormState>();
final TextEditingController _textNameController = new TextEditingController();
final TextEditingController _textPhoneController =
new TextEditingController();
String _selectBookType = "";
String title;
@override
void initState() {
_textNameController.text = widget._bookDetails.fullName;
}
@override
Widget build(BuildContext context) {
return BlocBuilder<LoginCubit, LoginState>(
builder: (context, state) {
return Scaffold(
appBar: AppBar(
title: Text("Add New Book"),
),
body: Container(
margin: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
padding: const EdgeInsets.all(20.0),
child: SingleChildScrollView(
child: bookForm(context),
),
),
);
},
);
}
Widget bookForm(BuildContext context) {
final format = DateFormat("yyyy-MM-dd");
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 10,),
FormBuilderRadio( activeColor: Colors.deepOrange,
decoration: InputDecoration(
labelText: 'Please Select Book type \*',
hintText: 'Please select book',
border: OutlineInputBorder(),
filled: true,
),
attribute: "book_type",
validators: [
FormBuilderValidators.required(),
],
options: [
"Yes",
"No",
]
.map((lang) => FormBuilderFieldOption(
value: lang,
child: Text(
lang,
),
))
.toList(growable: false),
),
SizedBox(height: 15,),
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: 4,
maxLength: 100,
/* controller: _textNameController,*/
decoration: const InputDecoration(
hintText: ' please add here the reason',
labelText: 'Select Reason',
border: OutlineInputBorder(),
),
validator: (value) {
if (value.isEmpty) {
return 'Please add remark ';
}
return null;
},
),
SizedBox(height: 10,),
SafeArea(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Container(
height: 80,
width: double.infinity,
padding: EdgeInsets.all(16),
child: FlatButton(
onPressed: () {
{
AwesomeDialog(
context: context,
animType: AnimType.LEFTSLIDE,
headerAnimationLoop: true,
dialogType: DialogType.SUCCES,
title: 'Successfully Submitted',
desc:
'Your data has been successfully submitted',
btnOkOnPress: () {
debugPrint('OnClcik');
},
btnOkIcon: Icons.check_circle,
onDissmissCallback: () {
debugPrint('Dialog Dissmiss from callback');
})
..show();
}
// It returns true if the form is valid, otherwise returns false
/* if (_formKey.currentState.validate()) {
print(_textPhoneController.value.text +
"->" +
_selectLeadType);
// If the form is valid, display a Snackbar.
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Data is in processing.')));
}*/
},
child: Text("SUBMIT",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),),
color: m_primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
),
),
)
,
],
),
);
}
}
答案 0 :(得分:1)
您可以使用Visibility
小部件。它接受一个bool
值。最初,您可以将其设置为false
,并且小部件将不可见;一旦单击单选按钮,您可以调用setState
并将{内的布尔值更改为true
{1}}回调。这将显示输入字段。
此外,它在库中指出onChanged
已过时,请使用FormBuilderRadio
。
FormBuilderRadioGroup