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;
    }
    
  • 相关阅读:
    WPF Style和Template
    WPF自定义命令
    Vue-cli proxyTable 解决开发环境的跨域问题
    mongoose 获取某个存在的collecion 里的数据
    express+mongodb+mongoose简单入门
    服务器环境配置nginx / php / php-fpm(一)
    vue 循环前十条数据
    nodejs express的基本用法
    nodejs querystring
    nodejs fs.readFile
  • 原文地址:https://www.cnblogs.com/ajanuw/p/11770671.html
Copyright © 2011-2022 走看看