How to update state of a ModalBottomSheet in Flutter?

前端 未结 4 2225
一个人的身影
一个人的身影 2020-12-03 02:40

This code is very simple: shows a modal bottom sheet and when the uses clicks the button, it increases the height of the sheet by 10.

But nothing happens. Actually,

4条回答
  •  情话喂你
    2020-12-03 03:14

    Screenshot:


    Create a class:

    class MyBottomSheet extends StatefulWidget {
      @override
      _MyBottomSheetState createState() => _MyBottomSheetState();
    }
    
    class _MyBottomSheetState extends State {
      bool _flag = false;
    
      @override
      Widget build(BuildContext context) {
        return Column(
          children: [
            FlutterLogo(
              size: 300,
              style: FlutterLogoStyle.stacked,
              textColor: _flag ? Colors.black : Colors.red,
            ),
            RaisedButton(
              onPressed: () => setState(() => _flag = !_flag),
              child: Text('Change Color'),
            )
          ],
        );
      }
    }
    

    Usage:

    showModalBottomSheet(
      context: context,
      builder: (_) => MyBottomSheet(),
    );
    

提交回复
热议问题