Techiio-author
Started by Peter DanielsOct 1, 2021

Closed
Is there a way to hide a container/elements after click on button in flutter?

4 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 4 VIEWES SHARE

As the title suggest I want to hide a container when button is clicked.

2 Replies

Techiio-commentatorNeel Dey replied 7 months ago0 likes0 dislikes

Try with this visibility

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
  runApp(MyApp());
}
class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
  bool visible = true;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        home: Scaffold(
          appBar: AppBar(
            title: Text("Test obviously"),
          ),
          body: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              TextButton(
                  onPressed: () {
                    setState(() {
                      visible = !visible;
                    });
                  },
                  child: Text("Click")),
              Visibility(
                  visible: visible,
                  child: Container(
                    height: 100,
                    color: Colors.green,
                  ))
            ],
          ),
        ));
  }
}
Techiio-commentatorPeter Daniels replied 7 months ago0 likes0 dislikes

Thanks for your suggestion.

This thread is closed by Peter Daniels
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance