zoukankan      html  css  js  c++  java
  • Flutter 创建透明的路由页面

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: HomePage(),
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Text('home page'),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.dialer_sip),
            onPressed: () {
              Navigator.of(context).push(SimpleRoute(
                name: 'aaa',
                title: 'aaa',
                builder: (_) {
                  return Scaffold(
                    backgroundColor: Colors.transparent,
                    body: Center(
                      child: Container(
                        padding: EdgeInsets.all(12.0),
                        color: Colors.black,
                        child: Text(
                          'data',
                          style: TextStyle(color: Colors.white),
                        ),
                      ),
                    ),
                  );
                },
              ));
            },
          ),
        );
      }
    }
    
    class SimpleRoute extends PageRoute {
      SimpleRoute({
        @required this.name,
        @required this.title,
        @required this.builder,
      }) : super(
              settings: RouteSettings(name: name),
            );
    
      final String title;
      final String name;
      final WidgetBuilder builder;
    
      @override
      String get barrierLabel => null;
    
      @override
      bool get opaque => false;
    
      @override
      bool get maintainState => true;
    
      @override
      Duration get transitionDuration => Duration(milliseconds: 0);
    
      @override
      Widget buildPage(
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
      ) {
        return Title(
          title: title,
          color: Theme.of(context).primaryColor,
          child: builder(context),
        );
      }
    
      /// 页面切换动画
      @override
      Widget buildTransitions(
        BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        Widget child,
      ) {
        return FadeTransition(
          opacity: animation,
          child: child,
        );
      }
    
      @override
      Color get barrierColor => null;
    }
    
  • 相关阅读:
    检测c/c++中内存泄露
    在一个集合S中寻找最大的C使A+B=C且A,B,C均在集合当中
    《为学》
    U盘windows无法格式化的解决办法
    java.lang.AbstractMethodError: oracle.jdbc.driver...解决方法
    sqlplus连接远程Oracle
    oracle字符集导致的乱码问题
    大端与小端存储模式详解
    《劝学》原文
    《报任安书》司马迁
  • 原文地址:https://www.cnblogs.com/ajanuw/p/11770671.html
Copyright © 2011-2022 走看看