Search
 
SCRIPT & CODE EXAMPLE
 

DART

add fullscreen modal on a page in flutter app

import 'package:flutter/material.dart';

class TutorialOverlay extends ModalRoute<void> {
  @override
  Duration get transitionDuration => Duration(milliseconds: 500);

  @override
  bool get opaque => false;

  @override
  bool get barrierDismissible => false;

  @override
  Color get barrierColor => Colors.black.withOpacity(0.5);

  @override
  String get barrierLabel => null;

  @override
  bool get maintainState => true;

  @override
  Widget buildPage(
      BuildContext context,
      Animation<double> animation,
      Animation<double> secondaryAnimation,
      ) {
    // This makes sure that text and other content follows the material style
    return Material(
      type: MaterialType.transparency,
      // make sure that the overlay content is not cut off
      child: SafeArea(
        child: _buildOverlayContent(context),
      ),
    );
  }

  Widget _buildOverlayContent(BuildContext context) {
    return Center(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            'This is a nice overlay',
            style: TextStyle(color: Colors.white, fontSize: 30.0),
          ),
          RaisedButton(
            onPressed: () => Navigator.pop(context),
            child: Text('Dismiss'),
          )
        ],
      ),
    );
  }

  @override
  Widget buildTransitions(
      BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
    // You can add your own animations for the overlay content
    return FadeTransition(
      opacity: animation,
      child: ScaleTransition(
        scale: animation,
        child: child,
      ),
    );
  }
}


// Example application:
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Playground',
      home: TestPage(),
    );
  }
}

class TestPage extends StatelessWidget {
  void _showOverlay(BuildContext context) {
    Navigator.of(context).push(TutorialOverlay());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Test')),
      body: Padding(
        padding: EdgeInsets.all(16.0),
        child: Center(
          child: RaisedButton(
            onPressed: () => _showOverlay(context),
            child: Text('Show Overlay'),
          ),
        ),
      ),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: onpressed pass context flutter 
Dart :: dart enums 
Dart :: dart double to int 
Dart :: signing the app flutter 
Dart :: align column to center of flex flutter 
Dart :: flutter check if null 
Dart :: flutter pageview show next page 
Dart :: Drawer Header set text positon 
Dart :: UserScrollNotification in flutter 
Dart :: flutter Explain Hot Reload in 
Dart :: list join dart 
Dart :: flutter button playing sound 
Dart :: adding animation in flutter 
Dart :: dark mode in flutter packages 
Dart :: var keys = snap.value.keys; 
Dart :: callback after last frame flutter 
Dart :: flutter add checkbox 
Dart :: bloc to bloc communication in flutter 
Dart :: flutter toast not working 
Dart :: dart format print 
Dart :: dart is operator 
Dart :: double to int in dart 
Swift :: swift text align center 
Swift :: Check if device is iPhone or not swift ios 
Swift :: swift rotate text 90 degrees 
Swift :: create alert in swift 
Swift :: round up swift 
Swift :: swift close app 
Swift :: swiftui console log 
Swift :: clone repo using jenkins pipeline 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =