dropdown error

    0

    0

    Edwin Budiyanto

    import 'package:flutter/material.dart';
    import 'package:hexcolor/hexcolor.dart';
    import 'package:moty_sos_apps/custom/input.dart';
    
    class EMemo extends StatefulWidget {
      const EMemo({super.key});
    
      @override
      State<EMemo> createState() => _EMemoState();
    }
    
    class _EMemoState extends State<EMemo> {
      late String? valKejadian;
      late String? valKategori;
      String? strKategoriId;
      List<String>? _getDdKejadian = [];
      late Map<String, String>? idKategori;
      bool? isAfterChoiceKejadian = false;
      void getKejadianPerKategori(valueKategori) {
        if (valKategori == valueKategori) {
          idKategori = ddKategoriKejadian
              .firstWhere((element) => element.values.elementAt(1) == valueKategori)
              .map((key, value) {
            return MapEntry(key, value);
          });
          idKategori!.map((key, value) => MapEntry(key, strKategoriId));
          setState(() {
            strKategoriId = idKategori?.values.elementAt(0) ?? "";
            _getDdKejadian = ddKejadian
                .where((element) =>
                    element.values.elementAt(2) == strKategoriId.toString())
                .map((e) => e.values.elementAt(1))
                .toList();
          });
        } else {
          setState(() {
            _getDdKejadian!.clear();
            _getDdKejadian = ddKejadian
                .where((element) =>
                    element.values.elementAt(2) == strKategoriId.toString())
                .map((e) => e.values.elementAt(1))
                .toList();
          });
        }
      }
    
      void initstate() {
        super.initState();
        getKejadianPerKategori(valKategori);
      }
    
      final List<String> ddProject = <String>[
        'Menara Saidah',
        'PT. Pembangunan Jaya Ancol',
        'PT. Synergi Oil',
        'PT. Maju Bangun Sejahtera'
      ];
    
      List<Map<String, String>> ddKategoriKejadian = <Map<String, String>>[
        {'id': '1', 'kategori': 'Non Criminal/bukan criminal'},
        {'id': '2', 'kategori': 'C-Safety/Keselamatan Kerja'},
        // {'id': '3', 'kategori': 'D-Indisiplinary / Tindakan tidak disiplin'},
        // {'id': '4', 'kategori': 'Client Complain / Keluhan Klien'},
      ];
    
      List<Map<String, String>> ddKejadian = <Map<String, String>>[
        {'id': '1', 'kejadian': 'Theft/Pencurian', 'id_kategori': '1'},
        {'id': '2', 'kejadian': 'Blockade/Blokade', 'id_kategori': '1'},
        {'id': '3', 'kejadian': 'Land Claim', 'id_kategori': '2'}
      ];
      final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
      TextEditingController project = TextEditingController();
      TextEditingController kategory = TextEditingController();
      TextEditingController kejadian = TextEditingController();
      TextEditingController shift = TextEditingController();
      TextEditingController keterangan = TextEditingController();
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: HexColor("#edf2f4"),
            appBar: AppBar(
              actions: [
                Icon(
                  Icons.menu,
                  color: HexColor("#2B2D42"),
                )
              ],
              elevation: 0,
              backgroundColor: HexColor("#2b2d42"),
              title: Center(
                  child: Text("Laporan Kejadian",
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          fontFamily: "Noto Serif",
                          fontWeight: FontWeight.bold,
                          fontStyle: FontStyle.italic,
                          color: HexColor("#edf2f4")))),
            ),
            body: Form(
              key: _formKey,
              child: Column(
                children: [
                  Container(
                    margin: const EdgeInsets.fromLTRB(50, 20, 50, 0),
                    child: InputDropDown(
                      hint: "Pilih Project",
                      label: 'Project',
                      // labelText: "test",
                      getData: ddProject,
                      getFilter: (value) {
                        valKejadian = null;
                      },
                      validators: (value) {
                        if (value == '' || value == null) {
                          return 'Mohon pilih project';
                        }
                        return null;
                      },
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.fromLTRB(50, 20, 50, 0),
                    child: InputDropDown(
                      hint: "Pilih Kategori Kejadian",
                      label: "Kategori Kejadian",
                      getData: ddKategoriKejadian.map((e) {
                        return e.values.elementAt(1);
                      }).toList(),
                      getFilter: (val) {
                        setState(() {
                          valKategori = val;
                        });
                        getKejadianPerKategori(valKategori);
                        //print(strKategoriId);
                        // print(ddKejadian
                        //     .where((element) =>
                        //         element.values.elementAt(2) ==
                        //         idKategori?.values.elementAt(0))
                        //     .map((e) => e.values.elementAt(1))
                        //     .toList());
                        // print(idKategori?.values.elementAt(0));
                        //print(getListPerKategori);
                      },
                      validators: (value) {
                        if (value == '' || value == null) {
                          return 'Mohon pilih kategori kejadian';
                        }
                        return null;
                      },
                    ),
                  ),
                  Container(
                    margin: const EdgeInsets.fromLTRB(50, 20, 50, 0),
                    child: InputDropDown(
                      hint: "Pilih Kejadian",
                      label: "Kejadian",
                      getData: _getDdKejadian ?? [],
                      getFilter: (value) {
                        valKejadian = value;
                      },
                      validators: (value) {
                        if (value == '' || value == null) {
                          return 'Mohon pilih kejadian';
                        }
                        return null;
                      },
                    ),
                  ),
                ],
              ),
            ));
      }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.