Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: A S2SingleSelection<String?> was used after being disposed. #52

Open
mauriciorocha opened this issue Mar 30, 2023 · 1 comment

Comments

@mauriciorocha
Copy link

I'm trying to override the choiceBuilder method and when I call the onTap function to be able to close the modal, it's returning this error when invoking the "closeModal()" and "onModalClose(true)" methods.

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: A S2SingleSelection<String?> was used after being disposed.
Once you have called dispose() on a S2SingleSelection<String?>, it can no longer be used.
#0 ChangeNotifier.debugAssertNotDisposed.
change_notifier.dart:157
#1 ChangeNotifier.debugAssertNotDisposed
change_notifier.dart:164
#2 ChangeNotifier.dispose
change_notifier.dart:323
#3 S2State.onModalClose
s2_state.dart:58
#4 S2SingleState.onModalClose
s2_single_state.dart:32
#5 S2State.showModal
s2_state.dart:797

My Code:

import 'package:avatars/avatars.dart';
import 'package:awesome_select/awesome_select.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:trackmoney/modules/bank_account/bank_account_form_controller.dart';
import 'package:trackmoney/modules/bank_account/widgets/select_bank_widget.dart';

class BankAccountFormPage extends GetView<BankAccountFormController> {
  const BankAccountFormPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Nova Conta'),
      ),
      floatingActionButton: FloatingActionButton(
        elevation: 12,
        child: const Icon(Icons.save),
        onPressed: () {},
      ),
      body: Obx(() {
        List<Map<String, dynamic>> listBank = [];
        for (var element in controller.banks) {
          if (element.code != null) {
            listBank.add(element.toMap());
          }
        }
        listBank.sort((a, b) {
          return (a['name']).compareTo(b['name']);
        });
        return Column(
          children: <Widget>[
            const SizedBox(height: 7),
            SmartSelect<String?>.single(
              title: 'Banco',
              placeholder: 'Escolha uma instituição financeira',
              selectedValue: controller.selectedBank.value,
              choiceDivider: true,
              modalType: S2ModalType.bottomSheet,
              groupEnabled: false,
              groupSortBy: S2GroupSort.byCountInDesc(),
              modalFilter: true,
              modalFilterAuto: true,
              modalFilterHint: "Pesquise o nome do Banco",
              choiceItems: S2Choice.listFrom<String, Map<String, dynamic>>(
                source: listBank,
                value: (index, item) => item['code'].toString(),
                title: (index, item) => item['name'] ?? '',
              ),
              onChange: (selected) {
                controller.selectedBank.value = selected.value!;
              },
              tileBuilder: (context, state) {
                return S2Tile<dynamic>(
                  title: state.titleWidget,
                  value: state.selected.toWidget(),
                  onTap: state.showModal,
                  isTwoLine: true,
                  leading: const CircleAvatar(),
                );
              },
              choiceBuilder: (context, s2SingleState, isSelected) {
                return Container(
                  padding: EdgeInsets.symmetric(
                    vertical: Get.height * 0.015,
                    horizontal: Get.width * 0.03,
                  ),
                  child: GestureDetector(
                    onTap: () {
                      controller.selectedBank.value =
                          isSelected.value.toString();

                      s2SingleState.closeModal();
                      s2SingleState.onModalClose(true);

                      // }
                    },
                    child: Row(
                      children: [
                        Avatar(
                          name: isSelected.title.toString(),
                          shape: AvatarShape.circle(25),
                          textStyle: TextStyle(
                            fontSize: Get.width * 0.030,
                          ),
                        ),
                        SizedBox(
                          width: Get.width * 0.02,
                        ),
                        Flexible(
                          child: Text(
                            isSelected.title.toString(),
                            style: TextStyle(
                              fontSize: Get.width * 0.023,
                              color: Theme.of(context).colorScheme.primary,
                            ),
                          ),
                        ),

                        // Text(
                        //   isSelected.title.toString(),

                        //   style: TextStyle(
                        //     fontSize: Get.width * 0.023,
                        //     color: Theme.of(context).colorScheme.primary,
                        //   ),
                        // ),
                      ],
                    ),
                  ),
                );
              },
            ),
          ],
        );
      }),
    );
  }
}


@miikhaaeel
Copy link

I also have this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants