Flutter 创建透明的路由页面

  • 原文
import 'package:flutter/material.dart';

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 animation,
      Animation secondaryAnimation,) {
    return Title(
      title: title,
      color: Theme
          .of(context)
          .primaryColor,
      child: builder(context),
    );
  }

  /// 页面切换动画
  @override
  Widget buildTransitions(BuildContext context,
      Animation animation,
      Animation secondaryAnimation,
      Widget child,) {
    return FadeTransition(
      opacity: animation,
      child: child,
    );
  }

  @override
  Color get barrierColor => null;
}

你可能感兴趣的:(Flutter 创建透明的路由页面)