Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to update switch tile within modal bottom sheet

We are trying to update a switch tile within a modal bottom and I suspect this is effecting the state somehow but I am not sure how to resolve this issue.

ListTile(
                  title: const Text('Transactional'),
                  subtitle: const Text('Email, Push, SMS'),
                  trailing: Icon(Icons.adaptive.arrow_forward),
                  onTap: () {
                    HapticFeedback.lightImpact();
                    showModalBottomSheet(
                      barrierColor: Colors.black.withOpacity(0.5),
                      enableDrag: true,
                      shape: const RoundedRectangleBorder(
                          borderRadius:
                              BorderRadius.vertical(top: Radius.circular(20))),
                      context: context,
                      builder: (context) {
                        // Using Wrap makes the bottom sheet height the height of the content.
                        // Otherwise, the height will be half the height of the screen.
                        return Wrap(alignment: WrapAlignment.center, children: [
                          bottomSheetBar(),
                          ListTile(
                            title: Text('Transactional',
                                style: Theme.of(context).textTheme.titleLarge),
                          ),
                          ListTile(
                            title: Text(
                                'Recieve important notifications about any payments, cancellations and about your acccount.',
                                style: Theme.of(context).textTheme.bodyMedium),
                          ),
                          SwitchListTile(
                            title: const Text('Push'),
                            value: _push,
                            onChanged: (bool value) {
                              setState(() {
                                _push = value;
                              });
                            },
                            // secondary: const Icon(Icons.lightbulb_outline),
                          ),
                          SwitchListTile(
                            title: const Text('Email'),
                            value: _email,
                            onChanged: (bool value) {
                              setState(() {
                                _email = value;
                              });
                            },
                            // secondary: const Icon(Icons.lightbulb_outline),
                          ),
                          SwitchListTile(
                            title: const Text('SMS'),
                            value: _sms,
                            onChanged: (bool value) {
                              setState(() {
                                _sms = value;
                              });
                            },
                            // secondary: const Icon(Icons.lightbulb_outline),
                          ),
                          ElevatedButton(
                              onPressed: () {}, child: const Text('Done')),
                          const SizedBox(height: 20),
                        ]);
                      },
                    );
                  },
                ),

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you could use the StatefulBuilder widget above the wrap and thus only update the state within it and not the entire modal

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading