|
| 1 | +//.title |
| 2 | +// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ |
| 3 | +// |
| 4 | +// Copyright © dev-cetera.com & contributors. |
| 5 | +// |
| 6 | +// The use of this source code is governed by an MIT-style license described in |
| 7 | +// the LICENSE file located in this project's root directory. |
| 8 | +// |
| 9 | +// See: https://opensource.org/license/mit |
| 10 | +// |
| 11 | +// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ |
| 12 | +//.title~ |
| 13 | + |
| 14 | +import '/_common.dart'; |
| 15 | + |
| 16 | +// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| 17 | + |
| 18 | +class StatefulRouteManager extends StatefulWidget { |
| 19 | + final RouteState Function()? initialRouteState; |
| 20 | + final RouteState Function() fallbackRouteState; |
| 21 | + final RouteState<Enum> Function()? errorState; |
| 22 | + final void Function(RouteController controller)? onControllerCreated; |
| 23 | + final List<RouteBuilder> builders; |
| 24 | + final bool clipToBounds; |
| 25 | + final TRouteWrapperFn? wrapper; |
| 26 | + |
| 27 | + const StatefulRouteManager({ |
| 28 | + super.key, |
| 29 | + this.initialRouteState, |
| 30 | + required this.fallbackRouteState, |
| 31 | + this.errorState, |
| 32 | + this.onControllerCreated, |
| 33 | + required this.builders, |
| 34 | + this.clipToBounds = false, |
| 35 | + this.wrapper, |
| 36 | + }); |
| 37 | + |
| 38 | + @override |
| 39 | + State<StatefulRouteManager> createState() => _StatefulRouteManagerState(); |
| 40 | +} |
| 41 | + |
| 42 | +class _StatefulRouteManagerState extends State<StatefulRouteManager> { |
| 43 | + late final RouteController _controller; |
| 44 | + |
| 45 | + @override |
| 46 | + void initState() { |
| 47 | + super.initState(); |
| 48 | + _controller = RouteController( |
| 49 | + initialRouteState: widget.initialRouteState, |
| 50 | + fallbackRouteState: widget.fallbackRouteState, |
| 51 | + errorRouteState: widget.errorState, |
| 52 | + builders: widget.builders, |
| 53 | + ); |
| 54 | + widget.onControllerCreated?.call(_controller); |
| 55 | + } |
| 56 | + |
| 57 | + @override |
| 58 | + Widget build(BuildContext context) { |
| 59 | + return RouteControllerProvider( |
| 60 | + controller: _controller, |
| 61 | + child: SyncPodBuilder( |
| 62 | + pod: Sync.okValue(_controller.pRouteState), |
| 63 | + cacheDuration: null, |
| 64 | + builder: (context, snapshot) { |
| 65 | + Widget child; |
| 66 | + UNSAFE: |
| 67 | + child = RepaintBoundary( |
| 68 | + child: _controller.buildScreen( |
| 69 | + context, |
| 70 | + snapshot.value.unwrap().unwrap(), |
| 71 | + ), |
| 72 | + ); |
| 73 | + if (widget.clipToBounds) { |
| 74 | + child = ClipRect(child: child); |
| 75 | + } |
| 76 | + return widget.wrapper?.call(context, child) ?? child; |
| 77 | + }, |
| 78 | + ), |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments