myanmar_administrative_areas 0.0.6 myanmar_administrative_areas: ^0.0.6 copied to clipboard
Myanmar Administrative Areas
import 'package:flutter/material.dart';
import 'package:myanmar_administrative_areas/myanmar_administrative_areas.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
String selectedValue1 = '';
String selectedValue2 = '';
String selectedValue3 = '';
List<String> items2 = [];
List<String> items3 = [];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Dropdown Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
buildDropdown1(),
const SizedBox(height: 16),
buildDropdown2(),
const SizedBox(height: 16),
buildDropdown3(),
],
),
),
),
);
}
Widget buildDropdown1() {
return DropdownButtonFormField<String>(
value: selectedValue1,
hint: const Text('ပြည်နယ် နှင့် တိုင်းရွေးပါ'),
onChanged: (String? value) {
setState(() {
selectedValue1 = value!;
selectedValue2 = '';
selectedValue3 = '';
items2 = townshipsMy[selectedValue1]!;
items3 = [];
});
},
items: divisionMy.map((String item) {
return DropdownMenuItem<String>(
value: item,
child: Text(item),
);
}).toList(),
);
}
Widget buildDropdown2() {
return DropdownButtonFormField<String>(
value: selectedValue2,
hint: Text('Select Option'),
onChanged: (String? value) {
setState(() {
selectedValue2 = value!;
selectedValue3 = '';
items3 = dropdown3Items[selectedValue1]![selectedValue2]!;
});
},
items: items2.map((String item) {
return DropdownMenuItem<String>(
value: item,
child: Text(item),
);
}).toList(),
);
}
Widget buildDropdown3() {
return DropdownButtonFormField<String>(
value: selectedValue3,
hint: Text('Select Choice'),
onChanged: (String? value) {
setState(() {
selectedValue3 = value!;
});
},
items: items3.map((String item) {
return DropdownMenuItem<String>(
value: item,
child: Text(item),
);
}).toList(),
);
}
}