zoukankan      html  css  js  c++  java
  • Transparent PageRoute in Flutter for displaying a (semi-) transparent page

    import 'package:flutter/widgets.dart';
    
    class TransparentRoute extends PageRoute<void> {
      TransparentRoute({
        @required this.builder,
        RouteSettings settings,
      })  : assert(builder != null),
            super(settings: settings, fullscreenDialog: false);
    
      final WidgetBuilder builder;
    
      @override
      bool get opaque => false;
    
      @override
      Color get barrierColor => null;
    
      @override
      String get barrierLabel => null;
    
      @override
      bool get maintainState => true;
    
      @override
      Duration get transitionDuration => Duration(milliseconds: 350);
    
      @override
      Widget buildPage(BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        final result = builder(context);
        return FadeTransition(
          opacity: Tween<double>(begin: 0, end: 1).animate(animation),
          child: Semantics(
            scopesRoute: true,
            explicitChildNodes: true,
            child: result,
          ),
        );
      }
    }
    

      

    Keep in mind that this would also create a custom transition animation and behave differently than the more complex MaterialPageRoute (e.g. the swipe-back gesture would not work with the current implementation on iOS).

    You could use it like this:

    Navigator.of(context).push(
        TransparentRoute(builder: (BuildContext context) => YourSecondPage())
    );
    

      

    For more info on the PageRoute and the different implementers, head over to https://docs.flutter.io/flutter/widgets/PageRoute-class.html

  • 相关阅读:
    Luogu P1169 [ZJOI2007]棋盘制作 及悬线法浅谈
    P4338 [ZJOI2018]历史 P3703 [SDOI2017]树点涂色 题解
    多省联考2020游记
    min_25筛基础
    斯特林数、贝尔数与伯努利数基础
    后缀数组笔记
    分治FFT学习笔记
    多项式运算表
    基本积分公式表
    THUWC2019游记
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10790904.html
Copyright © 2011-2022 走看看