74 lines
2.2 KiB
Dart
74 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:page_transition/page_transition.dart';
|
|
|
|
import '../about/internal/application/NavigatorType.dart';
|
|
|
|
/// Every screen transition in the app funnels through here. Destinations are
|
|
/// widget instances, not route names — there is no route table. Keeping one
|
|
/// choke point means a guard (session, device, connectivity) can be applied to
|
|
/// all routing by editing a single method.
|
|
class PeachNavigation {
|
|
void navigateToPage(NavigatorType type, dynamic path, BuildContext context) {
|
|
_runSec(context, type, path);
|
|
}
|
|
|
|
Future _runSec(BuildContext context, NavigatorType type, dynamic path) async {
|
|
switch (type) {
|
|
case NavigatorType.openFully:
|
|
Navigator.of(context).pushReplacement(
|
|
MaterialPageRoute(builder: (BuildContext context) => path),
|
|
);
|
|
break;
|
|
case NavigatorType.justOpen:
|
|
Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.size,
|
|
alignment: Alignment.center,
|
|
opaque: true,
|
|
child: path,
|
|
),
|
|
);
|
|
break;
|
|
case NavigatorType.replaceCurrent:
|
|
Navigator.pushReplacement(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.scale,
|
|
alignment: Alignment.center,
|
|
opaque: true,
|
|
curve: Curves.ease,
|
|
duration: const Duration(microseconds: 9000),
|
|
child: path,
|
|
),
|
|
);
|
|
break;
|
|
case NavigatorType.makeNewMain:
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.fade,
|
|
alignment: Alignment.center,
|
|
opaque: true,
|
|
child: path,
|
|
),
|
|
ModalRoute.withName('/'),
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// Opens [path] and returns whatever it pops with — the reload-on-return
|
|
/// channel: a child calls `Navigator.pop(context, true)` and the parent
|
|
/// refreshes on a truthy result.
|
|
Future<dynamic> navigateToPageWithData(
|
|
dynamic path,
|
|
BuildContext context,
|
|
) async {
|
|
return await Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => path),
|
|
);
|
|
}
|
|
}
|