-2

Im creating this modal for report bottomsheet. and I want to change background color on hover but it requires setstate in order to do so, how can I do it without setState? i asked chatGpt and it gave me this code. but its still gives error.

here is my code:

import 'package:flutter/material.dart';
import 'package:pre/utility/static.data.dart';
import 'package:pre/utility/theme.dart';
import 'package:pre/widgets/custom_button.widget.dart';
import 'package:pre/widgets/social_widget/report-message.widget.dart';

bool isHover = true;
messageButtomSheet(BuildContext context, String text) {
  showModalBottomSheet(
    backgroundColor: Colors.transparent,
    context: context,
    builder: (builder) {
      return Container(
        height: ScreenUnit.heigh(context) * 8,
        decoration: const BoxDecoration(
          color: white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.0),
            topRight: Radius.circular(10.0),
          ),
        ),
        child: Padding(
            padding: const EdgeInsets.only(
              top: 30,
              left: 20,
              right: 20,
              bottom: 30,
            ),
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    CustomIconButton(
                        iconButton: Icons.close,
                        iconsize: 20,
                        color: secondarytextColor),
                    const Text(''),
                    const Text('')
                  ],
                ),
                const Padding(
                  padding: const EdgeInsets.only(top: 4.0, bottom: 15),
                  child: Text(
                    '',
                    style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
                  ),
                ),
                Expanded(
                  flex: 2,
                  child: ListView.builder(
                    itemCount: 4,
                    itemBuilder: (context, index) {
                      return MouseRegion(
                        onHover: (event) {
                          setState(() {
                            isHover = true;
                          });
                        },
                        onExit: (event) {
                          setState(() {
                            isHover = false;
                          });
                        },
                        child: customButtom(
                            title:' report',
                            backgroundColor: isHover ? grey : white,
                            fontColor: black,
                            borderColor: black.withOpacity(0.5),
                            height: ScreenUnit.heigh(context) * 0.067,
                            margin: const EdgeInsets.only(bottom: 8),
                            onPress: () {}),
                      );
                    },
                  ),
                ),
                customButtom(
                    title: 'تۆمارکردن',
                    width: double.infinity,
                    height: ScreenUnit.heigh(context) * 0.067,
                    margin: const EdgeInsets.only(top: 20),
                    onPress: () {
                      ReportMessageButtomSheet(context, 'text');
                    })
              ],
            )),
      );
    },
  );
}

trying to give hover affect to this button. expecting to work with out putting it in stateful widget.

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
rawa
  • 9
  • 2
  • Wanting one widget to rebuild from another widget is generally the time you should be looking at some sort of state management solution, like RiverPod. – Randal Schwartz Feb 25 '23 at 19:49

1 Answers1

1

You can use StatefulBuilder to update dialog ui.

  showModalBottomSheet(
    backgroundColor: Colors.transparent,
    context: context,
    builder: (builder) {
      return StatefulBuilder(
        builder: (context, setState) =>  
            Container(
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56