LCOV - code coverage report
Current view: top level - src - beamer_location_builder.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 12 12 100.0 %
Date: 2021-06-08 01:09:24 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : 
       3             : import '../beamer.dart';
       4             : import 'utils.dart';
       5             : 
       6             : typedef LocationBuilder = BeamLocation Function(BeamState);
       7             : 
       8             : /// A pre-made builder to be used for [locationBuilder].
       9             : ///
      10             : /// Determines the appropriate [BeamLocation] from the list
      11             : /// and populates it with configured state.
      12             : class BeamerLocationBuilder implements Function {
      13           2 :   BeamerLocationBuilder({required this.beamLocations});
      14             : 
      15             :   /// List of all [BeamLocation]s that this builder handles.
      16             :   final List<BeamLocation> beamLocations;
      17             : 
      18           2 :   BeamLocation call(BeamState state) {
      19           8 :     return Utils.chooseBeamLocation(state.uri, beamLocations, data: state.data);
      20             :   }
      21             : }
      22             : 
      23             : /// A pre-made builder to be used for [locationBuilder].
      24             : ///
      25             : /// Creates a single [BeamLocation]; [SimpleBeamLocation]
      26             : /// and configures its [BeamLocation.buildPages] with appropriate [routes].
      27             : class SimpleLocationBuilder implements Function {
      28           6 :   SimpleLocationBuilder({required this.routes, this.builder});
      29             : 
      30             :   /// List of all routes this builder handles.
      31             :   final Map<dynamic, dynamic Function(BuildContext, BeamState)> routes;
      32             : 
      33             :   /// Used as a [BeamLocation.builder].
      34             :   Widget Function(BuildContext context, Widget navigator)? builder;
      35             : 
      36           6 :   BeamLocation call(BeamState state) {
      37          18 :     var matched = SimpleBeamLocation.chooseRoutes(state, routes.keys);
      38           6 :     if (matched.isNotEmpty) {
      39           6 :       return SimpleBeamLocation(
      40             :         state: state,
      41           6 :         routes: Map.fromEntries(
      42          36 :             routes.entries.where((e) => matched.containsKey(e.key))),
      43           6 :         navBuilder: builder,
      44             :       );
      45             :     } else {
      46           9 :       return NotFound(path: state.uri.path);
      47             :     }
      48             :   }
      49             : }

Generated by: LCOV version 1.14