0.3 C
London
Thursday, November 30, 2023

android – Customized drop down controller situation in flutter


I’m utilizing the customized dropdown in my cell app. The issue is when the checklist of that dropdown is empty then i’m displaying a container within the place of that dropdown. When the checklist has factor once more, customdropdown is once more proven however when i choose an possibility of that dropdown for the primary time the onChanged methodology will not be referred to as and typically refreshereportanalysisfilter() is named a number of time no matter onChanged getting referred to as solely as soon as. My full Code is connected right here.

import 'package deal:flutter/materials.dart';

Widget construct(BuildContext context) {
  closing _width = Get.width;
  closing _height = Get.top;
  return AppBackground(
    youngster: Scaffold(
      backgroundColor: Colours.clear,
      appBar: AppBar(
        title: Textual content(
          "Block-Sensible End result Evaluation",
        ),
        backgroundColor: ThemeColors.main,
      ),
      physique: LayoutBuilder(builder: (context, constraints) {
        return _isLoading
            ? const Heart(
                youngster: CircularProgressIndicator(),
              )
            : SingleChildScrollView(
                youngster: ConstrainedBox(
                  constraints: BoxConstraints(
                      minWidth: constraints.maxWidth,
                      minHeight: constraints.maxHeight),
                  youngster: IntrinsicHeight(
                    youngster: Column(
                      kids: [
                        Container(
                          width: _width,
                          height: 110,
                          color: Colors.transparent,
                          margin: EdgeInsets.only(
                              top: 10, bottom: 20, left: 10, right: 10),
                          child: Wrap(
                            direction: Axis.horizontal,
                            alignment: WrapAlignment.spaceEvenly,
                            // crossAxisAlignment: WrapCrossAlignment.center,
                            runAlignment: WrapAlignment.center,
                            runSpacing: 10,
                            // runAlignment: WrapAlignment.end,
                            children: [
                              Column(
                                // mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Text(
                                    "Select Term",
                                    style: TextStyle(
                                        color: ThemeColors.black,
                                        fontSize: 12,
                                        fontWeight: FontWeight.normal),
                                  ),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  GestureDetector(
                                    child: Container(
                                      width: _width * 0.35,
                                      height: 30,
                                      decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(18.0),
                                        color: ThemeColors.offwhite,
                                        border: Border.all(
                                            color: ThemeColors.secondary,
                                            width: 1.5),
                                      ),
                                      child: Padding(
                                        padding: const EdgeInsets.fromLTRB(
                                            8, 1, 8, 1),
                                        child: Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.spaceBetween,
                                          children: [
                                            Text(
                                              _date,
                                              style: TextStyle(
                                                  color: ThemeColors.black,
                                                  fontSize: 12,
                                                  fontWeight: FontWeight.w500),
                                            ),
                                            Icon(
                                              Icons.calendar_today_rounded,
                                              color: ThemeColors.black,
                                              size: 14.0,
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                    onTap: () async {
                                      closing chosen =
                                          await showMonthYearPicker(
                                        context: context,
                                        initialDate:
                                            DateFormat("MMM-yyyy").parse(_date),
                                        firstDate: DateTime(2023),
                                        lastDate: DateTime(2030),
                                        builder: (context, youngster) {
                                          return Theme(
                                            information: Theme.of(context).copyWith(
                                              colorScheme: ColorScheme.gentle(
                                                  main: ThemeColors
                                                      .main, // header background colour
                                                  onPrimary: Colours
                                                      .black, // header textual content colour
                                                  onSurface: ThemeColors
                                                      .secondary // physique textual content colour
                                                  ),
                                              textButtonTheme:
                                                  TextButtonThemeData(
                                                model: TextButton.styleFrom(
                                                  foregroundColor:
                                                      ThemeColors.main,
                                                ),
                                              ),
                                            ),
                                            youngster: youngster!,
                                          );
                                        },
                                      );

                                      _date = DateFormat('MMM-yyyy')
                                          .format(chosen!);

                                      await refreshReportAnalysiswithFilter();
                                      if (mounted) setState(() {});
                                    },
                                  ),
                                ],
                              ),
                              Column(
                                kids: [
                                  Text(
                                    "Filter School Type",
                                    style: TextStyle(
                                        color: ThemeColors.black,
                                        fontSize: 12,
                                        fontWeight: FontWeight.normal),
                                  ),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  SizedBox(
                                    width: _width * 0.35,
                                    height: 30.0,
                                    child: CustomDropdown(
                                      hintText: 'Select',
                                      fillColor: ThemeColors.offwhite,
                                      borderRadius: BorderRadius.circular(18.0),
                                      borderSide: BorderSide(
                                          color: ThemeColors.secondary,
                                          width: 1.5),
                                      hintStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      selectedStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      listItemStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      items:
                                          // ["Select"],
                                          _schoolTypeList.solid<String>(),
                                      controller: _schoolTypeController,
                                      onChanged: (worth) async {
                                        _classList.clear();
                                        _classController.clear();
                                        _classSubject.clear();
                                        _subjectController.clear();
                                        _subjectsList.clear();
                                        await getclass();
                                        // _subjectController =
                                        //     TextEditingController();
                                        if (mounted) setState(() {});
                                      },
                                    ),
                                  ),
                                ],
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.heart,
                                kids: [
                                  Text(
                                    "Filter Class",
                                    style: TextStyle(
                                        color: ThemeColors.black,
                                        fontSize: 12,
                                        fontWeight: FontWeight.normal),
                                  ),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  SizedBox(
                                    width: _width * 0.35,
                                    height: 30.0,
                                    child: CustomDropdown(
                                      hintText: 'Select',
                                      fillColor: ThemeColors.offwhite,
                                      borderRadius: BorderRadius.circular(18.0),
                                      borderSide: BorderSide(
                                          color: ThemeColors.secondary,
                                          width: 1.5),
                                      hintStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      selectedStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      listItemStyle: TextStyle(
                                          color: ThemeColors.black,
                                          fontSize: 12,
                                          fontWeight: FontWeight.w500),
                                      items:
                                          // ["Select"],
                                          _classList.solid<String>(),
                                      controller: _classController,
                                      onChanged: (worth) {
                                        _subjectController.clear();
                                        _subjectsList.clear();
                                        getSubjectList();
                                        _subjectController =
                                            TextEditingController();
                                        if (mounted) setState(() {});
                                      },
                                    ),
                                  ),
                                ],
                              ),
                              Column(
                                kids: [
                                  Text(
                                    "Filter Subject",
                                    style: TextStyle(
                                        color: ThemeColors.black,
                                        fontSize: 12,
                                        fontWeight: FontWeight.normal),
                                  ),
                                  SizedBox(
                                    height: 5,
                                  ),
                                  _subjectsList.isNotEmpty
                                      ? SizedBox(
                                          // key: Key(myKey),
                                          width: _width * 0.35,
                                          height: 30.0,
                                          child: CustomDropdown(
                                            // key: Key(myKey),
                                            hintText: 'Select',
                                            fillColor: ThemeColors.offwhite,
                                            borderRadius:
                                                BorderRadius.circular(18.0),
                                            borderSide: BorderSide(
                                                color: ThemeColors.secondary,
                                                width: 1.5),
                                            hintStyle: TextStyle(
                                                color: ThemeColors.black,
                                                fontSize: 12,
                                                fontWeight: FontWeight.w500),
                                            selectedStyle: TextStyle(
                                                color: ThemeColors.black,
                                                fontSize: 12,
                                                fontWeight: FontWeight.w500),
                                            listItemStyle: TextStyle(
                                                color: ThemeColors.black,
                                                fontSize: 12,
                                                fontWeight: FontWeight.w500),
                                            items:
                                                // ["Select"],
                                                _subjectsList.solid<String>(),
                                            controller: _subjectController,
                                            onChanged: (worth) async {
                                              await refreshReportAnalysiswithFilter();
                                              if (mounted) setState(() {});
                                            },
                                          ),
                                        )
                                      : Container(
                                          top: 30.0,
                                          width: _width * 0.35,
                                          ornament: BoxDecoration(
                                            colour: ThemeColors.offwhite,
                                            borderRadius:
                                                BorderRadius.round(18.0),
                                            border: Border.all(
                                              colour: ThemeColors.secondary,
                                              width: 1.5,
                                            ),
                                          ),
                                          youngster: Padding(
                                            padding: const EdgeInsets.symmetric(
                                                horizontal: 14.0),
                                            youngster: Row(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.heart,
                                              mainAxisAlignment:
                                                  MainAxisAlignment
                                                      .spaceBetween,
                                              kids: [
                                                Text(
                                                  "Select",
                                                  style: TextStyle(
                                                      color: ThemeColors.black,
                                                      fontSize: 13,
                                                      fontWeight:
                                                          FontWeight.w500),
                                                ),
                                                Icon(
                                                  Icons.keyboard_arrow_down,
                                                  color: Colors.black,
                                                  size: 19.0,
                                                ),
                                              ],
                                            ),
                                          )),
                                ],
                              ),
                            ],
                          ),
                        ),
                        _chartDataList.size != 0
                            ? Container(
                                colour: ThemeColors.littlewhite,
                                youngster: Column(
                                  kids: [
                                    Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: ClipRRect(
                                        borderRadius: BorderRadius.circular(30),
                                        child: Container(
                                          color: ThemeColors.offwhite,
                                          child: Column(
                                            children: [
                                              ScrollbarTheme(
                                                data: ScrollbarThemeData(
                                                  interactive: true,
                                                  mainAxisMargin: 16,
                                                  radius:
                                                      Radius.elliptical(3, 3),
                                                  showTrackOnHover: false,
                                                  thumbVisibility:
                                                      MaterialStatePropertyAll(
                                                          true),
                                                  thumbColor:
                                                      MaterialStatePropertyAll(
                                                          ThemeColors
                                                              .tableScroll),
                                                  thickness:
                                                      MaterialStateProperty.all(
                                                          4),
                                                  trackColor:
                                                      MaterialStateProperty.all<
                                                          Color>(Colors.green),
                                                ),
                                                child: Scrollbar(
                                                  scrollbarOrientation:
                                                      ScrollbarOrientation.top,
                                                  controller:
                                                      _yourScrollController,
                                                  child: SingleChildScrollView(
                                                    controller:
                                                        _yourScrollController,
                                                    scrollDirection:
                                                        Axis.horizontal,
                                                    child: DataTable(
                                                      horizontalMargin: 40,
                                                      headingRowColor:
                                                          MaterialStatePropertyAll(
                                                              ThemeColors
                                                                  .tableHeader),
                                                      columns: [
                                                        DataColumn(
                                                            label:
                                                                Text('Sl. no')),
                                                        DataColumn(
                                                            label:
                                                                Text('Block')),
                                                        DataColumn(
                                                            label:
                                                                Text('0-30%')),
                                                        DataColumn(
                                                            label:
                                                                Text('30-59%')),
                                                        DataColumn(
                                                            label:
                                                                Text('60-79%')),
                                                        DataColumn(
                                                            label: Text(
                                                                '80-100%')),
                                                      ],
                                                      rows: _chartDataList
                                                          .asMap()
                                                          .entries
                                                          .map((entry) {
                                                        return DataRow(
                                                          colour: entry.key %
                                                                      2 !=
                                                                  0
                                                              ? MaterialStatePropertyAll(
                                                                  Colours.gray[
                                                                      300])
                                                              : MaterialStatePropertyAll(
                                                                  Colours
                                                                      .clear),
                                                          cells: [
                                                            DataCell(Text((entry
                                                                        .key +
                                                                    1)
                                                                .toString())),
                                                            DataCell(Text(entry
                                                                .value
                                                                .blockName)),
                                                            DataCell(Text(entry
                                                                .value.per030
                                                                .toString())),
                                                            DataCell(Text(entry
                                                                .value.per3059
                                                                .toString())),
                                                            DataCell(Text(entry
                                                                .value.per6080
                                                                .toString())),
                                                            DataCell(Text(entry
                                                                .value.per80100
                                                                .toString())),
                                                          ],
                                                        );
                                                      }).toList(),
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                              )
                            : SizedBox()
                      ],
                    ),
                  ),
                ),
              );
      }),
    ),
  );
}

class ChartData {
  closing String blockName;
  closing double per030;
  closing double per3059;
  closing double per6080;
  closing double per80100;

  ChartData({
    required this.blockName,
    required this.per030,
    required this.per3059,
    required this.per6080,
    required this.per80100,
  });
}

Each time i’m assigning the _subjectController a brand new controller commented within the above code its working however i need to know what’s inflicting the problems and what would be the greatest observe to resolve it.

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here