Created
April 4, 2022 06:36
-
-
Save rido-ramadan/3c60a6afe93e1b18153324fe3874e3ae to your computer and use it in GitHub Desktop.
Multiple Conditional Widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| class ConditionalWidget extends StatefulWidget { | |
| const ConditionalWidget({Key? key}) : super(key: key); | |
| @override | |
| State<ConditionalWidget> createState() => _ConditionalWidgetState(); | |
| } | |
| class _ConditionalWidgetState extends State<ConditionalWidget> { | |
| bool _isShown = true; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: const Text('Conditional Widget'), | |
| ), | |
| body: Center( | |
| child: Column( | |
| mainAxisSize: MainAxisSize.min, | |
| children: [ | |
| // Multiple conditional | |
| if (_isShown) ... [ | |
| const Text('All text and button will disappear when button is pressed'), | |
| const SizedBox(height: 16), | |
| ElevatedButton( | |
| child: const Text('Hide Button'), | |
| onPressed: _hideButton, | |
| ), | |
| ], | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| void _hideButton() { | |
| setState(() { | |
| _isShown = false; | |
| }); | |
| } | |
| } | |
| void main() => runApp(const MaterialApp(home: ConditionalWidget())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment