Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Types
  • Functions
  • Oops
  • Collections
  • Sets
  • Dart Interview Questions
  • Fluter
  • Android
  • Kotlin
  • Kotlin Android
  • Android with Java
  • Android Studio
Open In App
Next Article:
PageView Widget in Flutter
Next article icon

OffStage Widget in Flutter

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Flutter provides an inbuilt widget called “Offstage”, which is been used to hide or show any widget programmatically depending on user action/event. Offstage Widget is a widget that lays the child out as if it was in the tree, but without painting anything, without making the child available for hit-testing, and without taking any room in the parent. In this article, we will learn about the OffStage widget & how to implement it.

Constructor:

Offstage({       Key? key,       this.offstage = true,       Widget? child   })

Properties:

OffStage Property: Accepts Boolean value. The child widget is hidden when the offstage property is set to true. Likewise, if the property is set to ‘false’, the child widget is shown.

Key: The widget key, is used to control if it should be replaced.

Child: The widget below this widget in the tree.

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Create an Appbar inside Scaffold Widget

Dart
import 'package:flutter/material.dart';  void main() {   runApp(const MyApp()); }  class MyApp extends StatelessWidget {   const MyApp({Key? key}) : super(key: key);    @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.green,       ),       home: const MyHomePage(),     );   } }  class MyHomePage extends StatefulWidget {   const MyHomePage({Key? key}) : super(key: key);    @override   State<MyHomePage> createState() => _MyHomePageState(); }  class _MyHomePageState extends State<MyHomePage> {   bool isHidden = false;   @override   Widget build(BuildContext context) {     return Scaffold(       //Creating appbar       appBar: AppBar(title: Text('GeeksforGeeks')),     );   } } 

Step 3: Create a Container and Wrap it with Offstage Widget

  • Create a container and give it height, width, and color properties.
  • Inside the child, of a  Container give it a Flutter Dash Icon.
  • Wrap Container with OffStage Widget and give offStage property.
Dart
import 'package:flutter/material.dart';  void main() {   runApp(const MyApp()); }  class MyApp extends StatelessWidget {   const MyApp({Key? key}) : super(key: key);    @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.green,       ),       home: const MyHomePage(),     );   } }  class MyHomePage extends StatefulWidget {   const MyHomePage({Key? key}) : super(key: key);    @override   State<MyHomePage> createState() => _MyHomePageState(); }  class _MyHomePageState extends State<MyHomePage> {   bool isHidden = false;   @override   Widget build(BuildContext context) {     return Scaffold(       //Creating appbar       appBar: AppBar(title: Text('GeeksforGeeks')),       body: Center(         child: Column(           mainAxisAlignment: MainAxisAlignment.center,           children: [             // Using Offstage Widget by Wrapping it with Container             Offstage(               offstage: isHidden,               child: Container(                 width: 100,                 height: 100,                 color: Colors.blue,                 child: Icon(                   Icons.flutter_dash,                   size: 70,                   color: Colors.black,                 ),               ),             ),             SizedBox(               height: 20,             ),           ],         ),       ),     );   } } 

Step 4: Creating an Elevated Button

  • Inside the Elevated Button, we have put logic in setState that if the value of isHidden is false make it true and show the Dash Image on the Screen. 
  • if the value of isHidden is true then hide the Dash Image on the Screen.
  • Add Sized Box property for spacing between Dash Icon and Elevated Button.
Dart
import 'package:flutter/material.dart';  void main() {   runApp(const MyApp()); }  class MyApp extends StatelessWidget {   const MyApp({Key? key}) : super(key: key);    @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.green,       ),       home: const MyHomePage(),     );   } }  class MyHomePage extends StatefulWidget {   const MyHomePage({Key? key}) : super(key: key);    @override   State<MyHomePage> createState() => _MyHomePageState(); }  class _MyHomePageState extends State<MyHomePage> {   bool isHidden = false;   @override   Widget build(BuildContext context) {     return Scaffold(       //Creating appbar       appBar: AppBar(         title: Text('GeeksforGeeks'),         centerTitle: true,       ),       body: Center(         child: Column(           mainAxisAlignment: MainAxisAlignment.center,           children: [             // Using Offstage Widget by Wrapping it with Container             Offstage(               offstage: isHidden,               child: Container(                 width: 100,                 height: 100,                 color: Colors.blue,                 child: Icon(                   Icons.flutter_dash,                   size: 70,                   color: Colors.black,                 ),               ),             ),             SizedBox(               height: 20,             ),             // creating elevated button and giving it the logic                     ElevatedButton(               onPressed: () {                 setState(() {                   isHidden = !isHidden;                 });               },               child: Text(isHidden ? 'Show' : 'Hide'),             )           ],         ),       ),     );   } } 

Output:


Next Article
PageView Widget in Flutter

A

ayurishchandna
Improve
Article Tags :
  • Dart
  • Flutter
  • Flutter-Widgets

Similar Reads

  • Table Widget in Flutter
    Table widget is used to display items in a table layout. There is no need to use Rows and Columns to create a table. If we have multiple rows with the same width of columns then Table widget is the right approach. SliverList or Column will be most suitable if we only want to have a single column. Th
    3 min read
  • PageView Widget in Flutter
    The PageView widget allows the user to transition between different screens in their flutter application. All you need to set it up are a PageViewController and a PageView. Constructor of PageView class:Syntax: PageView({Key key, Axis scrollDirection, bool reverse, PageController controller, ScrollP
    3 min read
  • RotatedBox Widget in Flutter
    The RotatedBox widget is used to rotate its child by an integral number of quarter turns. It is used to orient its child widgets into either horizontal or vertical orientation. Furthermore, it is very lightweight and can be used for designing various UI as it gives flexibility to the user over the D
    2 min read
  • Flutter - OctoImage Widget
    The OctoImage widget in Flutter requires an ImageProvider to display images in an application. The images in the OctoImage widget can be supplied with a Progress indicator or a Place holder for loading the Image in it. An OctoImage widget makes use of the Octosets which are nothing but the combinati
    4 min read
  • Flutter - Stateful Widget
    A Stateful Widget has states in it. To understand a Stateful Widget, you need to have a clear understanding of widgets and state management. A state can be defined as "an imperative changing of the user interface," and a widget is "an immutable description of the part of the user interface". To lear
    4 min read
  • Flutter - Stack Widget
    The Stack widget in Flutter is a powerful tool that allows for the layering of multiple widgets on top of each other. While layouts like Row and Column arrange widgets horizontally and vertically, respectively, Stack provides a solution when you need to overlay widgets. For instance, if you want to
    6 min read
  • Flutter - ListTile Widget
    The ListTile widget is used to populate a ListView in Flutter. It contains a title as well as leading or trailing icons. Let's understand this with the help of an example. The Constructor of the ListTile classListTile({ Key key, Widget leading, Widget title, Widget subtitle, Widget trailing, bool is
    4 min read
  • Opacity Widget in Flutter
    The Opacity widget that makes its child partially transparent. This class colors its child into an intermediate buffer and then merges the child back into the scene partially transparent. For values of opacity other than 0.0 and 1.0, this class is relatively expensive as it needs coloring the child
    2 min read
  • What is Widgets in Flutter?
    Flutter is Google's UI toolkit for crafting beautiful, natively compiled iOS and Android apps from a single code base. To build any application we start with widgets - The building block of Flutter applications. Widgets describe what their view should look like given their current configuration and
    5 min read
  • TextSpan Widget in Flutter
    TextSpan is an immutable span of text. It has style property to give style to the text. It is also having children property to add more text to this widget and give style to the children. Let's understand this with the help of an example. Constructors:Syntax: TextSpan({String text, List<InlineSpa
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences