LCOV - code coverage report
Current view: top level - src/ui/editor/pages/helper_editor/font_editor - font_editor_presenter.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 24 35 68.6 %
Date: 2020-12-04 18:41:24 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : import 'package:google_fonts/google_fonts.dart';
       3             : import 'package:mvvm_builder/mvvm_builder.dart';
       4             : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/font_editor.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/pickers/font_weight_picker/font_weight_picker_loader.dart';
       7             : 
       8             : class FontEditorDialogPresenter
       9             :     extends Presenter<FontEditorDialogModel, FontEditorDialogView> {
      10             :   final TextStyle actualTextStyle;
      11             :   final String fontFamilyKey;
      12             : 
      13           2 :   FontEditorDialogPresenter(
      14             :     FontEditorDialogView viewInterface, {
      15             :     @required this.actualTextStyle,
      16             :     this.fontFamilyKey,
      17           4 :   }) : super(FontEditorDialogModel(), viewInterface);
      18             : 
      19           2 :   @override
      20             :   void onInit() {
      21          10 :     this.viewModel.modifiedTextStyle = TextStyle().merge(actualTextStyle);
      22           6 :     this.viewModel.fontKeys = FontKeys(
      23          10 :       fontFamilyNameKey: (fontFamilyKey != null && fontFamilyKey.length > 0) ? fontFamilyKey : 'Montserrat',
      24             :       fontWeightNameKey:
      25           6 :           FontWeightMapper.toFontKey(actualTextStyle.fontWeight),
      26             :     );
      27             : 
      28           6 :     WidgetsBinding.instance.addPostFrameCallback(afterFirstLayout);
      29             :   }
      30             : 
      31           2 :   void afterFirstLayout(Duration duration) {
      32             :     // Override color to be always visible!
      33           4 :     this.viewModel.modifiedTextStyle = this
      34           2 :         .viewModel
      35           2 :         .modifiedTextStyle
      36           6 :         .merge(this.viewInterface.defaultTextFieldPreviewColor());
      37           2 :     this.refreshView();
      38             :   }
      39             : 
      40           2 :   void changeFontSize(double fontSize) async {
      41          10 :     this.viewModel.modifiedTextStyle = this.viewModel.modifiedTextStyle.merge(
      42           2 :         TextStyle(fontSize: fontSize),
      43             :     );
      44           2 :     this.refreshView();
      45             :   }
      46             : 
      47           1 :   void changeFontFamily(BuildContext context) async {
      48           3 :     final String fontKey = await this.viewInterface.openFontFamilyPicker(
      49             :           context,
      50           2 :           this.viewModel.fontKeys,
      51             :         );
      52             : 
      53             :     if (fontKey == null) {
      54             :       return;
      55             :     }
      56           0 :     this.viewModel.fontKeys.fontFamilyNameKey = fontKey;
      57           0 :     this.viewModel.modifiedTextStyle = this
      58           0 :         .viewModel
      59           0 :         .modifiedTextStyle
      60           0 :         .merge(GoogleFonts.asMap()[fontKey].call());
      61           0 :     this.refreshView();
      62             :   }
      63             : 
      64           1 :   void changeFontWeight(BuildContext context) async {
      65             :     final MapEntry<String, FontWeight> fontWeightMap =
      66           3 :         await this.viewInterface.openFontWeightPicker(
      67             :               context,
      68           2 :               this.viewModel.fontKeys,
      69             :             );
      70             : 
      71             :     if (fontWeightMap == null) {
      72             :       return;
      73             :     }
      74           0 :     this.viewModel.fontKeys.fontWeightNameKey = fontWeightMap.key;
      75           0 :     this.viewModel.modifiedTextStyle = this.viewModel.modifiedTextStyle.merge(
      76           0 :           TextStyle(
      77           0 :             fontWeight: fontWeightMap.value,
      78             :           ),
      79             :         );
      80           0 :     this.refreshView();
      81             :   }
      82             : }

Generated by: LCOV version 1.14