Speed Dial Builder in Flutter
Code :
class VehicleSpeedDial extends StatefulWidget {
const VehicleSpeedDial({Key? key}) : super(key: key);
static const _vehicleNames = <String>[
'foot',
'hike',
'wheelchair',
'bike',
'racingbike',
'bike2',
'mtb',
'car',
'car4wd',
'motorcycle'
];
static const _icons = <IconData>[
Icons.directions_walk,
Icons.hiking,
Icons.wheelchair_pickup,
Icons.pedal_bike,
Icons.electric_bike_outlined,
Icons.bike_scooter,
Icons.directions_bike_outlined,
Icons.car_repair,
Icons.car_repair_outlined,
Icons.motorcycle
];
@override
State<VehicleSpeedDial> createState() => _VehicleSpeedDialState();
}
class _VehicleSpeedDialState extends State<VehicleSpeedDial> {
ValueNotifier<bool> isDialOpen = ValueNotifier(false);
@override
Widget build(BuildContext context) {
List<SpeedDialChild> speedDialChilds = [];
for (var i = 0; i < VehicleSpeedDial._vehicleNames.length; i++) {
speedDialChilds.add(SpeedDialChild(
child: Icon(VehicleSpeedDial._icons[i]),
label: VehicleSpeedDial._vehicleNames[i],
onTap: () {
print(VehicleSpeedDial._vehicleNames[i]);
}));
}
return WillPopScope(
onWillPop: () async {
if (isDialOpen.value) {
isDialOpen.value = false;
return false;
} else {
return true;
}
},
child: SpeedDial(
animatedIcon: AnimatedIcons.menu_close,
openCloseDial: isDialOpen,
backgroundColor: Colors.redAccent,
overlayColor: Colors.grey,
overlayOpacity: 0.5,
spacing: 15,
spaceBetweenChildren: 15,
closeManually: true,
children: speedDialChilds,
));
}
}
Comments
Post a Comment