Created
July 11, 2023 02:31
-
-
Save gonexwind/ca52128423b8f77747c37054b89abf52 to your computer and use it in GitHub Desktop.
Dropdown Example using Flutter Bloc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_bloc/flutter_bloc.dart'; | |
import '../../../data/models/order/courier.dart'; | |
import '../../blocs/order/order_bloc.dart'; | |
class DropdownExample extends StatefulWidget { | |
const DropdownExample({super.key}); | |
@override | |
State<DropdownExample> createState() => _DropdownExampleState(); | |
} | |
class _DropdownExampleState extends State<DropdownExample> { | |
Courier? _selectedCourier; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
children: [ | |
SizedBox(height: 200), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Builder(builder: (context) { | |
final couriers = context.watch<OrderBloc>().state.couriers; | |
return DropdownButton( | |
hint: Text("Select Courier"), | |
value: _selectedCourier, | |
items: couriers.map((item) { | |
return DropdownMenuItem( | |
child: Text(item.namaKurir ?? ''), | |
value: item, | |
); | |
}).toList(), | |
onChanged: (value) { | |
setState(() { | |
_selectedCourier = value; | |
}); | |
}, | |
); | |
}), | |
ElevatedButton( | |
child: Text('SUBMIT'), | |
onPressed: () { | |
print( | |
'SELECTED: ${_selectedCourier?.id} - ${_selectedCourier?.namaKurir}'); | |
}, | |
), | |
], | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment