LCOV - code coverage report
Current view: top level - src/ui/editor/pages/helper_editor/font_editor - font_editor.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 75 75 100.0 %
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:mvvm_builder/mvvm_builder.dart';
       4             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/font_editor_presenter.dart';
       5             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/font_editor_viewmodel.dart';
       6             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/font_list_tile.dart';
       7             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/font_size_picker.dart';
       8             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_family_picker/font_family_picker.dart';
       9             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_weight_picker/font_weight_picker.dart';
      10             : 
      11             : typedef OnCancelPicker = void Function();
      12             : 
      13             : typedef OnValidatePicker = void Function();
      14             : 
      15             : abstract class FontEditorDialogView {
      16             :   Future<String> openFontFamilyPicker(
      17             :     BuildContext context,
      18             :     FontKeys fontKeys,
      19             :   );
      20             :   Future<MapEntry<String, FontWeight>> openFontWeightPicker(
      21             :     BuildContext context,
      22             :     FontKeys fontKeys,
      23             :   );
      24             :   TextStyle defaultTextFieldPreviewColor();
      25             : }
      26             : 
      27             : 
      28             : 
      29             : class FontEditorDialogPage extends StatelessWidget implements FontEditorDialogView {
      30             : 
      31             :   final OnCancelPicker onCancelPicker;
      32             : 
      33             :   final OnValidatePicker onValidatePicker;
      34             : 
      35             :   final TextStyle actualTextStyle;
      36             : 
      37             :   final String fontFamilyKey;
      38             : 
      39             :   final Function(TextStyle, FontKeys) onFontModified;
      40             : 
      41           2 :   FontEditorDialogPage({
      42             :     Key key,
      43             :     @required TextStyle actualTextStyle,
      44             :     this.fontFamilyKey,
      45             :     this.onCancelPicker,
      46             :     this.onFontModified,
      47             :     this.onValidatePicker,
      48           2 :   }) : this.actualTextStyle = actualTextStyle.copyWith(),
      49           2 :        super(key: key);
      50             : 
      51             :   final _mvvmPageBuilder = MVVMPageBuilder<FontEditorDialogPresenter, FontEditorDialogModel>();
      52             : 
      53           2 :   @override
      54             :   Widget build(BuildContext context) {
      55           4 :     return _mvvmPageBuilder.build(
      56           2 :       key: UniqueKey(),
      57             :       context: context,
      58           4 :       presenterBuilder: (context) => FontEditorDialogPresenter(
      59             :         this,
      60           2 :         actualTextStyle: actualTextStyle,
      61           2 :         fontFamilyKey: fontFamilyKey,
      62             :       ),
      63           2 :       builder: (context, presenter, model) {
      64           2 :         return this._buildPage(
      65           2 :           context.buildContext,
      66             :           presenter,
      67             :           model,
      68             :         );
      69             :       },
      70             :     );
      71             :   }
      72             : 
      73           2 :   Widget _buildPage(
      74             :     final BuildContext context,
      75             :     final FontEditorDialogPresenter presenter,
      76             :     final FontEditorDialogModel model,
      77             :   ) {
      78           2 :     return AlertDialog(
      79           2 :       actions: _buildActions(model),
      80           2 :       content: SingleChildScrollView(
      81           2 :         child: Container(
      82             :           width: double.maxFinite,
      83           2 :           child: Column(
      84             :               mainAxisSize: MainAxisSize.min,
      85           2 :               children: [
      86           2 :                 Text(
      87             :                   'Preview',
      88           2 :                   key: ValueKey('pal_FontEditorDialog_Preview'),
      89           2 :                   style: model.modifiedTextStyle,
      90             :                   maxLines: 1,
      91             :                   overflow: TextOverflow.ellipsis,
      92             :                   textAlign: TextAlign.center,
      93             :                 ),
      94           2 :                 FontSizePicker(
      95           2 :                   style: model.modifiedTextStyle,
      96           2 :                   onFontSizeSelected: presenter.changeFontSize,
      97             :                 ),
      98           2 :                 Divider(),
      99           2 :                 ConstrainedBox(
     100           2 :                   constraints: BoxConstraints(
     101           8 :                     maxHeight: MediaQuery.of(context).size.height * 0.4,
     102             :                   ),
     103           2 :                   child: ListView(
     104           2 :                     key: ValueKey('pal_FontEditorDialog_List'),
     105             :                     shrinkWrap: true,
     106           2 :                     children: [
     107           2 :                       FontListTile(
     108           2 :                         key: ValueKey('pal_FontEditorDialog_List_FontFamily'),
     109             :                         title: 'Font family',
     110           4 :                         subTitle: model.fontKeys.fontFamilyNameKey,
     111           1 :                         onTap: () async {
     112           1 :                           HapticFeedback.selectionClick();
     113           1 :                           presenter.changeFontFamily(context);
     114             :                         },
     115             :                       ),
     116           2 :                       FontListTile(
     117           2 :                         key: ValueKey('pal_FontEditorDialog_List_FontWeight'),
     118             :                         title: 'Font weight',
     119           4 :                         subTitle: model.fontKeys.fontWeightNameKey,
     120           1 :                         onTap: () async {
     121           1 :                           HapticFeedback.selectionClick();
     122           1 :                           presenter.changeFontWeight(context);
     123             :                         },
     124             :                       ),
     125             :                     ],
     126             :                   ),
     127             :                 ),
     128             :               ],
     129             :             ),
     130             :           ),
     131             :         ),
     132             :     );
     133             :   }
     134             : 
     135           2 :   _buildActions(final FontEditorDialogModel model) {
     136           2 :     return [
     137           2 :       FlatButton(
     138           2 :         key: ValueKey('pal_FontEditorDialog_CancelButton'),
     139           2 :         child: Text('Cancel'),
     140           1 :         onPressed: () {
     141           1 :           HapticFeedback.selectionClick();
     142           2 :           this.onCancelPicker();
     143             :         },
     144             :       ),
     145           2 :       FlatButton(
     146           2 :         key: ValueKey('pal_FontEditorDialog_ValidateButton'),
     147           2 :         child: Text(
     148             :           'Validate',
     149           2 :           style: TextStyle(
     150             :             fontWeight: FontWeight.bold,
     151             :           ),
     152             :         ),
     153           1 :         onPressed: () {
     154           1 :           HapticFeedback.selectionClick();
     155           1 :           if (onFontModified != null) {
     156           2 :             onFontModified(
     157           5 :               model.modifiedTextStyle.merge(TextStyle(color: actualTextStyle.color)),
     158           1 :               model.fontKeys,
     159             :             );
     160             :           }
     161           2 :           onValidatePicker();
     162             :         },
     163             :       ),
     164             :     ];
     165             :   }
     166             : 
     167             :   @override
     168           1 :   Future<String> openFontFamilyPicker(
     169             :     BuildContext context,
     170             :     FontKeys fontKeys,
     171             :   ) async {
     172           2 :     return await Navigator.pushNamed(
     173             :       context,
     174             :       '/editor/new/font-family',
     175           1 :       arguments: FontFamilyPickerArguments(
     176           1 :         fontFamilyName: fontKeys.fontFamilyNameKey,
     177           1 :         fontWeightName: fontKeys.fontWeightNameKey,
     178             :       ),
     179             :     ) as String;
     180             :   }
     181             : 
     182             :   @override
     183           1 :   Future<MapEntry<String, FontWeight>> openFontWeightPicker(
     184             :     BuildContext context,
     185             :     FontKeys fontKeys,
     186             :   ) async {
     187           2 :     return await Navigator.pushNamed(
     188             :       context,
     189             :       '/editor/new/font-weight',
     190           1 :       arguments: FontWeightPickerArguments(
     191           1 :         fontFamilyName: fontKeys.fontFamilyNameKey,
     192           1 :         fontWeightName: fontKeys.fontWeightNameKey,
     193             :       ),
     194             :     ) as MapEntry<String, FontWeight>;
     195             :   }
     196             : 
     197           2 :   @override
     198           4 :   TextStyle defaultTextFieldPreviewColor() => TextStyle(color: Color(0xFF03045E));
     199             : }

Generated by: LCOV version 1.14