LCOV - code coverage report
Current view: top level - src - pal.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 41 49 83.7 %
Date: 2020-12-04 18:41:24 Functions: 0 0 -

          Line data    Source code
       1             : library pal;
       2             : 
       3             : import 'package:flutter/material.dart';
       4             : import 'package:pal/src/injectors/editor_app/editor_app_context.dart';
       5             : import 'package:pal/src/injectors/editor_app/editor_app_injector.dart';
       6             : import 'package:pal/src/injectors/user_app/user_app_context.dart';
       7             : import 'package:pal/src/injectors/user_app/user_app_injector.dart';
       8             : import 'package:pal/src/ui/client/helper_orchestrator.dart';
       9             : import 'package:pal/src/ui/editor/pal_editmode_wrapper.dart';
      10             : 
      11             : import 'injectors/editor_app/editor_app_injector.dart';
      12             : import 'pal_navigator_observer.dart';
      13             : 
      14             : // our production server address
      15             : const String PAL_SERVER_URL = const String.fromEnvironment("SERVER_URL", defaultValue: "http://217.182.88.6:9040");
      16             : 
      17             : // Pal top widget
      18             : class Pal extends StatelessWidget {
      19             : 
      20             :   /// application child to display Pal over it.
      21             :   final MaterialApp childApp;
      22             : 
      23             :   /// reference to the Navigator state of the child app
      24             :   final GlobalKey<NavigatorState> navigatorKey;
      25             : 
      26             :   /// used to manage state of current page
      27             :   final PalNavigatorObserver navigatorObserver;
      28             : 
      29             :   /// disable or enable the editor mode.
      30             :   final bool editorModeEnabled;
      31             : 
      32             :   /// text direction of your application.
      33             :   final TextDirection textDirection;
      34             : 
      35             :   /// set the application token to interact with the server.
      36             :   final String appToken;
      37             : 
      38           7 :   Pal({
      39             :     Key key,
      40             :     @required this.childApp,
      41             :     @required this.appToken,
      42             :     this.editorModeEnabled = true,
      43             :     this.textDirection = TextDirection.ltr,
      44           0 :   }) : assert(childApp != null, 'Pal must embbed a client application'),
      45           7 :      assert(childApp.navigatorKey != null, 'Pal navigatorKey must not be null'),
      46           7 :      navigatorKey = childApp.navigatorKey,
      47          28 :      navigatorObserver = childApp.navigatorObservers.firstWhere((element) => element is PalNavigatorObserver),
      48           7 :      super(key: key) {
      49           7 :      assert(navigatorObserver != null, 'A navigator Observer of type PalObserver must be added to your MaterialApp');
      50           7 :      _init();
      51             :   }
      52             : 
      53           0 :   Pal.fromRouterApp({
      54             :     Key key,
      55             :     @required this.childApp,
      56             :     @required this.appToken,
      57             :     this.editorModeEnabled = true,
      58             :     this.navigatorKey,
      59             :     this.textDirection = TextDirection.ltr,
      60           0 :   }) : assert(childApp != null, 'Pal must embbed a client application'),
      61           0 :       assert(navigatorKey != null, 'Pal navigatorKey must not be null'),
      62           0 :       navigatorObserver = PalNavigatorObserver.instance(),
      63           0 :       super(key: key) {
      64           0 :     assert(navigatorObserver != null, 'A navigator Observer of type PalObserver must be added to your MaterialApp');
      65           0 :     _init();
      66             :   }
      67             : 
      68           7 :   _init() {
      69          14 :     debugPrint("-- init Pal plugin --");
      70          21 :     debugPrint("starting on server $PAL_SERVER_URL");
      71             :     // TODO refactoring split client Key and editor Key
      72           7 :     if(editorModeEnabled) {
      73          12 :       EditorAppContext.init(url: PAL_SERVER_URL, token: this.appToken);
      74             :     } else {
      75           4 :       UserAppContext.init(url: PAL_SERVER_URL, token: this.appToken);
      76             :     }
      77             :   }
      78             : 
      79           7 :   @override
      80             :   Widget build(BuildContext context) {
      81           7 :     return Directionality(
      82           7 :       textDirection: textDirection,
      83           7 :       child: (editorModeEnabled)
      84           6 :           ? buildEditorApp()
      85           2 :           : buildUserApp(),
      86             :     );
      87             :   }
      88             : 
      89           6 :   Widget buildEditorApp() {
      90           6 :     return EditorInjector(
      91           6 :       routeObserver: navigatorObserver,
      92           6 :       hostedAppNavigatorKey: navigatorKey,
      93           6 :       child: PalEditModeWrapper(
      94           6 :         userApp: childApp,
      95           6 :         hostedAppNavigatorKey: navigatorKey,
      96             :       ),
      97           6 :       boundaryChildKey: navigatorKey,
      98           6 :       appContext: EditorAppContext.instance
      99             :     );
     100             :   }
     101             : 
     102           2 :   Widget buildUserApp() {
     103           2 :     return UserInjector(
     104           2 :         routeObserver: navigatorObserver,
     105           2 :         child: Builder(
     106           2 :           builder: (context) {
     107           2 :             HelperOrchestrator.getInstance(
     108           4 :               helperClientService: UserInjector.of(context).helperService,
     109           4 :               inAppUserClientService: UserInjector.of(context).inAppUserClientService,
     110           4 :               helpersSynchronizer: UserInjector.of(context).helpersSynchronizerService,
     111           2 :               routeObserver: navigatorObserver,
     112           2 :               navigatorKey: navigatorKey
     113             :             );
     114           2 :             return childApp;
     115             :           }
     116             :         ),
     117           2 :         appContext: UserAppContext.instance,
     118             :       );
     119             :   }
     120             : 
     121             : 
     122             : }
     123             : 

Generated by: LCOV version 1.14