Reputation: 339
I try to call the widget form and when I call it inside the view class, it shows an error and I don't know what's wrong with the code.
I'm already importing the class and I can't figure out why would it show an error when I call _AllFieldsForm
widget inside another widget.
Here's the _AllFieldsForm()
class _AllFieldsForm extends StatefulWidget {
const _AllFieldsForm({Key? key}) : super(key: key);
@override
AllFieldsForm createState() => AllFieldsForm();
}
class AllFieldsForm extends State<_AllFieldsForm> {
//const AllFieldsForm({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => AllFieldsFormBloc(),
child: Builder(
builder: (context) {
final formBloc = BlocProvider.of<AllFieldsFormBloc>(context);
return Theme(
data: Theme.of(context).copyWith(
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
child: Scaffold(
body: FormBlocListener<AllFieldsFormBloc, String, String>(
onSubmitting: (context, state) {
LoadingDialog.show(context);
},
onSuccess: (context, state) {
LoadingDialog.hide(context);
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const SuccessScreen()));
},
onFailure: (context, state) {
LoadingDialog.hide(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.failureResponse!)));
},
child: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
TextFieldBlocBuilder(
textFieldBloc: formBloc.text1,
decoration: const InputDecoration(
labelText: 'TextFieldBlocBuilder',
prefixIcon: Icon(Icons.text_fields),
),
),
DropdownFieldBlocBuilder<String>(
selectFieldBloc: formBloc.select1,
decoration: const InputDecoration(
labelText: 'DropdownFieldBlocBuilder222',
prefixIcon: Icon(Icons.sentiment_satisfied),
),
itemBuilder: (context, value) => FieldItem(
child: Text(value),
),
),
Upvotes: 1
Views: 205
Reputation: 458
You have used _ while creating class that refers to a private class so you can not use a private class as publically any other files so use like this :
class AllFieldsForm extends StatefulWidget {
const AllFieldsForm({Key? key}) : super(key: key);
@override
_AllFieldsForm createState() => _AllFieldsForm();
}
class _AllFieldsForm extends State<AllFieldsForm> {
@override
Widget build(BuildContext context){
return Scaffold();
}
}
Upvotes: 2
Reputation: 710
you can create private class that why problem is occur.
Create a Class like this :
class AllFieldsForm extends StatefulWidget {
const AllFieldsForm({Key? key}) : super(key: key);
@override
AllFieldsForm createState() => AllFieldsForm();
}
Upvotes: 1