LCOV - code coverage report
Current view: top level - src/widgets - navigator_builder.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 16 28 57.1 %
Date: 2022-10-22 16:29:45 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : 
       3             : import '../destination.dart';
       4             : import '../navigation_controller.dart';
       5             : 
       6             : /// Builds a widget that wraps a content for [NavigationController].
       7             : ///
       8             : /// See also:
       9             : /// - [DefaultNavigatorBuilder]
      10             : /// - [BottomNavigationBuilder]
      11             : ///
      12             : abstract class NavigatorBuilder {
      13             :   /// Returns a widget that wraps a content of navigator's destinations.
      14             :   ///
      15             :   Widget build(BuildContext context, NavigationController navigator);
      16             : }
      17             : 
      18             : /// Implementation of [NavigatorBuilder] that wraps destination's content into
      19             : /// [Navigator] widget.
      20             : ///
      21             : class DefaultNavigatorBuilder implements NavigatorBuilder {
      22             :   /// Creates default navigator builder.
      23             :   ///
      24           9 :   const DefaultNavigatorBuilder();
      25             : 
      26           2 :   @override
      27             :   Widget build(BuildContext context, NavigationController navigator) {
      28           2 :     final pages = <_TheseusPage>[];
      29           8 :     for (int i = 0; i < navigator.stack.length; i++) {
      30           4 :       final destination = navigator.stack[i];
      31           4 :       pages.add(_TheseusPage(
      32           6 :         key: ValueKey('${destination.uri}-$i'),
      33             :         destination: destination,
      34             :       ));
      35             :     }
      36           2 :     return Navigator(
      37           2 :       key: navigator.key,
      38             :       pages: pages,
      39           0 :       onPopPage: (route, result) {
      40           0 :         navigator.goBack();
      41           0 :         route.didPop(result);
      42             :         return true;
      43             :       },
      44             :     );
      45             :   }
      46             : }
      47             : 
      48             : class _TheseusPage extends Page {
      49           2 :   const _TheseusPage({
      50             :     required this.destination,
      51             :     required LocalKey key,
      52           2 :   }) : super(key: key);
      53             : 
      54             :   final Destination destination;
      55             : 
      56           2 :   @override
      57             :   Route createRoute(BuildContext context) {
      58           6 :     switch (destination.configuration.transition) {
      59           2 :       case DestinationTransition.material:
      60           2 :         return MaterialPageRoute(
      61             :           settings: this,
      62           6 :           builder: (context) => destination.build(context),
      63             :         );
      64           0 :       case DestinationTransition.custom:
      65           0 :         return PageRouteBuilder(
      66             :           settings: this,
      67           0 :           pageBuilder: (context, animation, secondaryAnimation) =>
      68           0 :               destination.build(context),
      69           0 :           transitionsBuilder: destination.configuration.transitionBuilder!,
      70             :         );
      71             :       case DestinationTransition.none:
      72             :       default:
      73           0 :         return PageRouteBuilder(
      74             :           settings: this,
      75           0 :           pageBuilder: (context, animation, secondaryAnimation) =>
      76           0 :               destination.build(context),
      77           0 :           transitionsBuilder: (context, animation, secondaryAnimation, child) =>
      78             :               child,
      79             :         );
      80             :     }
      81             :   }
      82             : }

Generated by: LCOV version