52 lines
1.1 KiB
Dart
52 lines
1.1 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
Future<T> routeToPage<T extends Object>(BuildContext context, Widget page) {
|
|
if (Platform.isAndroid) {
|
|
return Navigator.of(context).push(
|
|
_buildPageRoute(page),
|
|
);
|
|
} else {
|
|
return Navigator.of(context).push(
|
|
MaterialPageRoute(
|
|
builder: (BuildContext context) {
|
|
return page;
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
void replacePage(BuildContext context, Widget page) {
|
|
Navigator.of(context).pushReplacement(
|
|
_buildPageRoute(page),
|
|
);
|
|
}
|
|
|
|
PageRouteBuilder<T> _buildPageRoute<T extends Object>(Widget page) {
|
|
return PageRouteBuilder(
|
|
pageBuilder: (
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
) {
|
|
return page;
|
|
},
|
|
transitionsBuilder: (
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
Widget child,
|
|
) {
|
|
return Align(
|
|
child: FadeTransition(
|
|
opacity: animation,
|
|
child: child,
|
|
),
|
|
);
|
|
},
|
|
transitionDuration: Duration(milliseconds: 200),
|
|
opaque: false,
|
|
);
|
|
}
|