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

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:flutter/services.dart';
       3             : import 'package:pal/src/theme.dart';
       4             : import 'package:pal/src/ui/shared/widgets/circle_button.dart';
       5             : 
       6             : class ToolbarAction {
       7             :   final Key key;
       8             :   final Function onTap;
       9             :   final IconData icon;
      10             : 
      11           0 :   ToolbarAction(
      12             :     this.key,
      13             :     this.onTap,
      14             :     this.icon,
      15             :   );
      16             : }
      17             : 
      18             : class EditHelperToolbar extends StatelessWidget {
      19             :   final Function onChangeTextFont;
      20             :   final Function onChangeTextColor;
      21             :   final Function onChangeBorder;
      22             :   final Function onCloseTap;
      23             :   final num bottomPadding;
      24             :   final List<ToolbarAction> extraActions;
      25             : 
      26             :   final _toolbarHeight = 40.0;
      27             :   final _iconsRadius = 25.0;
      28             : 
      29           5 :   const EditHelperToolbar({
      30             :     Key key,
      31             :     this.onChangeTextFont,
      32             :     this.onChangeTextColor,
      33             :     this.onChangeBorder,
      34             :     this.onCloseTap,
      35             :     this.bottomPadding = 8.0,
      36             :     this.extraActions,
      37           5 :   }) : super(key: key);
      38             : 
      39           4 :   factory EditHelperToolbar.text({
      40             :     Key key,
      41             :     Function onChangeTextFont,
      42             :     Function onChangeTextColor,
      43             :     Function onClose,
      44             :     num bottomPadding = 8.0,
      45             :   }) {
      46           4 :     return EditHelperToolbar(
      47             :       onChangeTextFont: onChangeTextFont,
      48             :       onChangeTextColor: onChangeTextColor,
      49             :       onCloseTap: onClose,
      50             :       bottomPadding: bottomPadding,
      51             :     );
      52             :   }
      53             : 
      54           0 :   factory EditHelperToolbar.border({
      55             :     Key key,
      56             :     Function onChangeTextFont,
      57             :     Function onChangeTextColor,
      58             :     Function onChangeBorder,
      59             :     Function onClose,
      60             :     num bottomPadding = 8.0,
      61             :   }) {
      62           0 :     return EditHelperToolbar(
      63             :         onChangeTextFont: onChangeTextFont,
      64             :         onChangeTextColor: onChangeTextColor,
      65             :         onCloseTap: onClose,
      66             :         bottomPadding: bottomPadding,
      67           0 :         extraActions: [
      68           0 :           ToolbarAction(
      69           0 :             ValueKey('pal_EditHelperToolbar_ChangeBorder'),
      70             :             onChangeBorder,
      71             :             Icons.border_outer,
      72             :           )
      73             :         ]);
      74             :   }
      75             : 
      76           5 :   @override
      77             :   Widget build(BuildContext context) {
      78           5 :     return Padding(
      79          10 :       padding: EdgeInsets.only(bottom: bottomPadding),
      80           5 :       child: Container(
      81           5 :         key: ValueKey('pal_EditHelperToolbar'),
      82           5 :         height: _toolbarHeight,
      83          10 :         color: PalTheme.of(context).toolbarBackgroundColor,
      84           5 :         child: Padding(
      85             :           padding: const EdgeInsets.symmetric(horizontal: 6.0),
      86           5 :           child: Row(
      87             :             mainAxisAlignment: MainAxisAlignment.spaceBetween,
      88           5 :             children: [
      89           5 :               Flexible(
      90           5 :                 child: SingleChildScrollView(
      91             :                   scrollDirection: Axis.horizontal,
      92           5 :                   child: Wrap(
      93             :                     spacing: 4.0,
      94             :                     runSpacing: 4.0,
      95           5 :                     children: [
      96           5 :                       CircleIconButton(
      97           5 :                         key: ValueKey('pal_EditHelperToolbar_TextColor'),
      98          10 :                         radius: _toolbarHeight / 2,
      99             :                         backgroundColor: Colors.transparent,
     100           0 :                         onTapCallback: () {
     101           0 :                           HapticFeedback.selectionClick();
     102             : 
     103           0 :                           if (onChangeTextColor != null) {
     104           0 :                             onChangeTextColor();
     105             :                           }
     106             :                         },
     107           5 :                         icon: Icon(
     108             :                           Icons.format_color_text,
     109             :                           color: Colors.white,
     110           5 :                           size: _iconsRadius,
     111             :                         ),
     112             :                       ),
     113           5 :                       CircleIconButton(
     114           5 :                         key: ValueKey('pal_EditHelperToolbar_TextFont'),
     115          10 :                         radius: _toolbarHeight / 2,
     116             :                         backgroundColor: Colors.transparent,
     117           0 :                         onTapCallback: () {
     118           0 :                           HapticFeedback.selectionClick();
     119             : 
     120           0 :                           if (onChangeTextFont != null) {
     121           0 :                             onChangeTextFont();
     122             :                           }
     123             :                         },
     124           5 :                         icon: Icon(
     125             :                           Icons.font_download,
     126             :                           color: Colors.white,
     127           5 :                           size: _iconsRadius,
     128             :                         ),
     129             :                       ),
     130           5 :                       if (extraActions != null && extraActions.length > 0)
     131           0 :                         Wrap(
     132             :                           spacing: 4.0,
     133             :                           runSpacing: 4.0,
     134           0 :                           children: _buildExtraActions(),
     135             :                         ),
     136             :                       // TODO: Create factory to add some extra actions like border
     137             :                     ],
     138             :                   ),
     139             :                 ),
     140             :               ),
     141           5 :               CircleIconButton(
     142           5 :                 key: ValueKey('pal_EditHelperToolbar_Close'),
     143          10 :                 radius: _toolbarHeight / 2,
     144             :                 backgroundColor: Colors.transparent,
     145           1 :                 onTapCallback: () {
     146           1 :                   HapticFeedback.selectionClick();
     147             : 
     148           1 :                   if (onCloseTap != null) {
     149           2 :                     onCloseTap();
     150             :                   }
     151             :                 },
     152           5 :                 icon: Icon(
     153             :                   Icons.close,
     154             :                   color: Colors.white,
     155           5 :                   size: _iconsRadius,
     156             :                 ),
     157             :               ),
     158             :             ],
     159             :           ),
     160             :         ),
     161             :       ),
     162             :     );
     163             :   }
     164             : 
     165           0 :   List<Widget> _buildExtraActions() {
     166           0 :     List<Widget> children = [];
     167           0 :     for (final ToolbarAction action in extraActions) {
     168           0 :       children.add(
     169           0 :         CircleIconButton(
     170           0 :           key: action.key,
     171           0 :           radius: _toolbarHeight / 2,
     172             :           backgroundColor: Colors.transparent,
     173           0 :           onTapCallback: () {
     174           0 :             HapticFeedback.selectionClick();
     175             : 
     176           0 :             if (action.onTap != null) {
     177           0 :               action.onTap();
     178             :             }
     179             :           },
     180           0 :           icon: Icon(
     181           0 :             action.icon,
     182             :             color: Colors.white,
     183           0 :             size: _iconsRadius,
     184             :           ),
     185             :         ),
     186             :       );
     187             :     }
     188             :     return children;
     189             :   }
     190             : }

Generated by: LCOV version 1.14