Skip to content

Instantly share code, notes, and snippets.

@mopilo
Last active November 24, 2021 07:27
Show Gist options
  • Save mopilo/68836cb64ef5daf813890f04c68857d1 to your computer and use it in GitHub Desktop.
Save mopilo/68836cb64ef5daf813890f04c68857d1 to your computer and use it in GitHub Desktop.
dropdown
void _business() async {
_locationBloc.add(GetState()); //get states here
List<StateModel> states = [];
List<LGAModel> lgas = [];
showGeneralDialog(
barrierDismissible: false,
barrierColor: Colors.grey,
transitionDuration: Duration(milliseconds: 200),
context: context,
pageBuilder: (context, Animation animation, Animation secondAnimation) =>
StatefulBuilder(builder: (context, setState) {
return Scaffold(
body: BlocListener(
cubit: _locationBloc,
listener: (context, state) {
if (state is LocationInitial) {}
if (state is LocationSuccess) {
setState(() {
states = state.states;
});
}
if (state is LocationLGASuccess) {
setState(() {
lgas = state.lgas;
});
}
if (state is LocationFailure) {}
},
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: BMColors.blue,
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
child: Container(
margin: EdgeInsets.all(20),
child: Column(crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.all(10),
alignment: Alignment.topRight,
child: IconButton(
icon: Icon(Icons.close, size: 30),
color: Colors.white,
onPressed: (){Navigator.pop(context);},
),
),
TextWidget(
text: 'Set Location',
size: FontSize.s32,
appcolor: Colors.white,
type: 'Circular',
),
Expanded(child: SizedBox(height: 20)),
InputWidget(
obscure: false,
hint: 'Street Address',
controller: _streetController,
validator: validateInput,
keyboard: TextInputType.text,
),
SizedBox(height: SizeConfig.sizeSmall),
Container(
height: 60,
decoration: BoxDecoration(
color: BMColors.bg,
borderRadius: BorderRadius.circular(5),
),
// margin: EdgeInsets.only(top: 0, left: 0),
child: DropdownButtonHideUnderline(
child: Container(
alignment: Alignment.centerLeft,
margin: const EdgeInsets.symmetric(horizontal: 20),
child: DropdownButton(
isExpanded: true,
hint: Text(
'State',
textAlign: TextAlign.left,
),
value: _city,
items: states.map((value) {
return new DropdownMenuItem<String>(
value: value.id,
child: new Text(value.name),
);
}).toList(),
onChanged: (value) {
var name = states.firstWhere((i) => i.id == value).name;
setState(() {
_city = value;
_busniessLocationController = TextEditingController(text: name);
_lga = "1";
lgas.clear();
});
_locationBloc.add(GetLGA(id: value)); //get lga here
},
),
)
),
),
SizedBox(height: SizeConfig.sizeSmall),
Container(
height: 60,
decoration: BoxDecoration(
color: BMColors.bg,
borderRadius: BorderRadius.circular(5),
),
// margin: EdgeInsets.only(top: 0, left: 0),
child: DropdownButtonHideUnderline(
child: Container(
alignment: Alignment.centerLeft,
margin: const EdgeInsets.symmetric(horizontal: 20),
child: DropdownButton(
isExpanded: true,
hint: Text(
'LGA',
textAlign: TextAlign.left,
),
value: _lga,
items: lgas.map((value) {
return new DropdownMenuItem<String>(
value: value.id,
child: new Text(value.name),
);
}).toList(),
onChanged: (value) {
print(value);
var localGovt = lgas.firstWhere((i) => i.id == value).name;
setState(() {
_lga = value;
_busniessLocationLGAController = TextEditingController(text: localGovt);
});
},
),
)),
),
SizedBox(height: SizeConfig.sizeLarge),
Container(
width: double.infinity,
height: SizeConfig.sizeXXXL,
child: FlatButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(SizeConfig.sizeExtraSmall)),
padding: EdgeInsets.all(SizeConfig.sizeMedium),
color: BMColors.buttonColor,
child: TextWidget(
text: 'Save',
appcolor: BMColors.white,
size: FontSize.s16,
type: 'Circular',
),
onPressed: () {
if (_lga != null &&
_city != null &&
_streetController.text != null) {
setState(() {
busStreet = _streetController.text;
businessLga = _busniessLocationLGAController.text;
businessState = _busniessLocationController.text;
});
Navigator.pop(context);
}
},
),
),
Expanded(child: SizedBox(height: 20)),
]),
),
),
)),
));
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment