LCOV - code coverage report
Current view: top level - src/ui/editor - pal_editmode_wrapper.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 56 58 96.6 %
Date: 2020-12-04 18:41:24 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:pal/src/injectors/editor_app/editor_app_injector.dart';
       3             : import 'package:pal/src/pal_notifications.dart';
       4             : import 'package:pal/src/router.dart';
       5             : import 'package:pal/src/services/pal/pal_state_service.dart';
       6             : import 'package:pal/src/theme.dart';
       7             : import 'package:pal/src/ui/editor/pages/helpers_list/helpers_list_modal.dart';
       8             : import 'package:pal/src/ui/editor/widgets/bubble_overlay.dart';
       9             : import 'package:pal/src/ui/shared/widgets/overlayed.dart';
      10             : 
      11             : class PalEditModeWrapper extends StatefulWidget {
      12             :   // this is the client embedded application that wanna use our Pal
      13             :   final MaterialApp userApp;
      14             : 
      15             :   final GlobalKey<NavigatorState> hostedAppNavigatorKey;
      16             : 
      17           6 :   PalEditModeWrapper({@required this.userApp, this.hostedAppNavigatorKey});
      18             : 
      19           6 :   @override
      20           6 :   _PalEditModeWrapperState createState() => _PalEditModeWrapperState();
      21             : }
      22             : 
      23             : class _PalEditModeWrapperState extends State<PalEditModeWrapper> {
      24             :   final GlobalKey _repaintBoundaryKey = GlobalKey();
      25             : 
      26             :   PalEditModeStateService palEditModeStateService;
      27             : 
      28           6 :   @override
      29             :   void didChangeDependencies() {
      30           6 :     super.didChangeDependencies();
      31           6 :     palEditModeStateService =
      32          18 :         EditorInjector.of(context).palEditModeStateService;
      33          12 :     palEditModeStateService.showEditorBubble
      34          12 :         .addListener(_onShowBubbleStateChanged);
      35             :   }
      36             : 
      37           6 :   @override
      38             :   void dispose() {
      39           6 :     super.dispose();
      40           6 :     if (palEditModeStateService != null) {
      41          12 :       palEditModeStateService.showEditorBubble
      42          12 :           .removeListener(_onShowBubbleStateChanged);
      43             :     }
      44             :   }
      45             : 
      46           6 :   @override
      47             :   Widget build(BuildContext context) {
      48           6 :     return PalTheme(
      49           6 :       theme: PalThemeData.light(),
      50           6 :       child: Overlayed(
      51           6 :         child: Builder(
      52          12 :           builder: (context) => MaterialApp(
      53           6 :             navigatorKey: palNavigatorGlobalKey,
      54             :             debugShowCheckedModeBanner: false,
      55           0 :             onGenerateRoute: (RouteSettings settings) => route(settings),
      56          12 :             theme: PalTheme.of(context).buildTheme(),
      57           6 :             home: LayoutBuilder(
      58           6 :               builder: (context, constraints) {
      59           6 :                 return NotificationListener<PalGlobalNotification>(
      60           1 :                   onNotification: (notification) {
      61           1 :                     if (notification is ShowHelpersListNotification) {
      62           0 :                       _showHelpersListModal(context);
      63           1 :                     } else if (notification is ShowBubbleNotification) {
      64           4 :                       palEditModeStateService.showEditorBubble.value = notification.isVisible;
      65             :                     }
      66             :                     return true;
      67             :                   },
      68           6 :                   child: Stack(
      69           6 :                     key: ValueKey('pal_MainStack'),
      70           6 :                     children: [
      71             :                       // The app
      72           6 :                       RepaintBoundary(
      73           6 :                         key: _repaintBoundaryKey,
      74          12 :                         child: widget.userApp,
      75             :                       ),
      76             :                       // Build the floating widget above the app
      77           6 :                       BubbleOverlayButton(
      78           6 :                         key: ValueKey('palBubbleOverlay'),
      79          12 :                         visibility: palEditModeStateService.showEditorBubble,
      80           6 :                         screenSize: Size(
      81           6 :                           constraints.maxWidth,
      82           6 :                           constraints.maxHeight,
      83             :                         ),
      84           2 :                         onTapCallback: () => _showHelpersListModal(context),
      85             :                       ),
      86             :                     ],
      87             :                   ),
      88             :                 );
      89             :               },
      90             :             ),
      91             :           ),
      92             :         ),
      93             :       ),
      94             :     );
      95             :   }
      96             : 
      97           1 :   _onShowBubbleStateChanged() {
      98           1 :     if (mounted)
      99           2 :       setState(() {});
     100             :   }
     101             : 
     102           1 :   _showHelpersListModal(BuildContext context) {
     103           1 :     BorderRadius borderRadius = BorderRadius.only(
     104           1 :       topLeft: Radius.circular(25.0),
     105           1 :       topRight: Radius.circular(25.0),
     106             :     );
     107             : 
     108           1 :     showModalBottomSheet(
     109             :       context: context,
     110             :       barrierColor: Colors.black26,
     111           1 :       shape: RoundedRectangleBorder(
     112             :         borderRadius: borderRadius,
     113             :       ),
     114           1 :       builder: (BuildContext bottomSheetContext) {
     115           1 :         return ClipRRect(
     116             :           borderRadius: borderRadius,
     117           1 :           child: HelpersListModal(
     118           1 :             repaintBoundaryKey: _repaintBoundaryKey,
     119           2 :             hostedAppNavigatorKey: widget.hostedAppNavigatorKey,
     120             :             bottomModalContext: bottomSheetContext,
     121             :           ),
     122             :         );
     123             :       },
     124             :     );
     125             :   }
     126             : }

Generated by: LCOV version 1.14