myanmar_administrative_areas 0.0.7 copy "myanmar_administrative_areas: ^0.0.7" to clipboard
myanmar_administrative_areas: ^0.0.7 copied to clipboard

Myanmar Administrative Areas

example/lib/main.dart

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: const Text('Dropdown Example'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(32.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            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 = townshipsMy[selectedValue1]![0];
          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: const Text('မြို့နယ်ရွေးပါ'),
      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(),
  //   );
  // }
}