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/theme.dart';
5 : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_weight_picker/font_weight_picker_presenter.dart';
6 : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_weight_picker/font_weight_picker_viewmodel.dart';
7 :
8 : class FontWeightPickerArguments {
9 : String fontFamilyName;
10 : String fontWeightName;
11 :
12 2 : FontWeightPickerArguments({
13 : @required this.fontFamilyName,
14 : @required this.fontWeightName,
15 : });
16 : }
17 :
18 : abstract class FontWeightPickerView {}
19 :
20 : /// Use this picker with FontEditor dialog only
21 : class FontWeightPickerPage extends StatelessWidget
22 : implements FontWeightPickerView {
23 : final FontWeightPickerArguments arguments;
24 :
25 1 : FontWeightPickerPage({
26 : Key key,
27 : @required this.arguments,
28 : });
29 :
30 : final _mvvmPageBuilder =
31 : MVVMPageBuilder<FontWeightPickerPresenter, FontWeightPickerModel>();
32 :
33 1 : @override
34 : Widget build(BuildContext context) {
35 2 : return _mvvmPageBuilder.build(
36 1 : key: UniqueKey(),
37 : context: context,
38 2 : presenterBuilder: (context) => FontWeightPickerPresenter(
39 : this,
40 1 : arguments,
41 : ),
42 1 : builder: (context, presenter, model) {
43 1 : return Scaffold(
44 1 : key: ValueKey('pal_FontWeightPicker'),
45 1 : appBar: AppBar(
46 1 : title: Text('Font weight'),
47 : ),
48 2 : body: this._buildPage(context.buildContext, presenter, model),
49 : );
50 : },
51 : );
52 : }
53 :
54 1 : Widget _buildPage(
55 : final BuildContext context,
56 : final FontWeightPickerPresenter presenter,
57 : final FontWeightPickerModel model,
58 : ) {
59 1 : return ListView.builder(
60 1 : key: ValueKey('pal_FontWeightPicker_ListView'),
61 : shrinkWrap: true,
62 2 : itemCount: model.fontWeights.length,
63 1 : itemBuilder: (context, index) {
64 3 : final map = model.fontWeights.entries.elementAt(index);
65 :
66 : TextStyle originalFontStyle =
67 3 : GoogleFonts.getFont(arguments.fontFamilyName);
68 1 : TextStyle modifiedFontStyle = originalFontStyle.merge(
69 1 : TextStyle(
70 : fontSize: 23.0,
71 1 : fontWeight: map.value,
72 : ),
73 : );
74 :
75 1 : return ListTile(
76 2 : key: ValueKey('pal_FontWeightPicker_ListView_ListTile$index'),
77 1 : title: Text(
78 1 : map.key,
79 : style: modifiedFontStyle,
80 : ),
81 3 : trailing: (map.key == model.selectedFontWeightKey)
82 1 : ? Icon(
83 : Icons.check,
84 2 : key: ValueKey('pal_FontWeightPicker_ListView_ListTile_Check$index'),
85 3 : color: PalTheme.of(context).colors.dark,
86 : )
87 : : null,
88 0 : onTap: () {
89 0 : Navigator.pop(context, map);
90 : },
91 : );
92 : },
93 : );
94 : }
95 : }
|