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_family_picker/font_family_picker_loader.dart';
6 : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_family_picker/font_family_picker_presenter.dart';
7 : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_family_picker/font_family_picker_viewmodel.dart';
8 :
9 : class FontFamilyPickerArguments {
10 : String fontFamilyName;
11 : String fontWeightName;
12 :
13 2 : FontFamilyPickerArguments({
14 : @required this.fontFamilyName,
15 : @required this.fontWeightName,
16 : });
17 : }
18 :
19 : abstract class FontFamilyPickerView {}
20 :
21 : /// Use this picker with FontEditor dialog only
22 : class FontFamilyPickerPage extends StatelessWidget
23 : implements FontFamilyPickerView {
24 : final FontFamilyPickerArguments arguments;
25 : final FontFamilyPickerLoader loader;
26 :
27 1 : FontFamilyPickerPage({
28 : Key key,
29 : this.loader,
30 : @required this.arguments,
31 : });
32 :
33 : final _mvvmPageBuilder =
34 : MVVMPageBuilder<FontFamilyPickerPresenter, FontFamilyPickerModel>();
35 : final TextEditingController _searchController = TextEditingController();
36 :
37 1 : @override
38 : Widget build(BuildContext context) {
39 2 : return _mvvmPageBuilder.build(
40 1 : key: ValueKey('pal_FontFamilyPickerBuilder'),
41 : context: context,
42 2 : presenterBuilder: (context) => FontFamilyPickerPresenter(
43 : this,
44 1 : loader ?? FontFamilyPickerLoader(),
45 1 : arguments,
46 : ),
47 1 : builder: (context, presenter, model) {
48 1 : return Scaffold(
49 1 : key: ValueKey('pal_FontFamilyPicker'),
50 1 : appBar: AppBar(
51 1 : title: Text('Font family'),
52 : ),
53 2 : body: this._buildPage(context.buildContext, presenter, model),
54 : );
55 : },
56 : );
57 : }
58 :
59 1 : Widget _buildPage(
60 : final BuildContext context,
61 : final FontFamilyPickerPresenter presenter,
62 : final FontFamilyPickerModel model,
63 : ) {
64 1 : return SafeArea(
65 1 : child: Column(
66 1 : children: [
67 1 : Padding(
68 : padding: const EdgeInsets.all(13.0),
69 1 : child: TextField(
70 1 : key: ValueKey('pal_FontFamilyPicker_SearchBarField'),
71 1 : controller: _searchController,
72 1 : onChanged: (String newValue) {
73 1 : presenter.filterSearchResults(newValue);
74 : },
75 1 : decoration: InputDecoration(
76 : labelText: 'Search',
77 : hintText: 'Search',
78 1 : prefixIcon: Icon(Icons.search),
79 1 : border: OutlineInputBorder(
80 1 : borderRadius: BorderRadius.all(
81 1 : Radius.circular(25.0),
82 : ),
83 : ),
84 : ),
85 : ),
86 : ),
87 1 : Expanded(
88 1 : child: !model.isLoading
89 1 : ? ListView.builder(
90 1 : key: ValueKey('pal_FontFamilyPicker_ListView'),
91 : shrinkWrap: true,
92 2 : itemCount: model.fonts.length,
93 1 : itemBuilder: (context, index) {
94 2 : final String key = model.fonts[index];
95 :
96 1 : TextStyle originalFontStyle = GoogleFonts.getFont(key);
97 1 : TextStyle modifiedFontStyle = originalFontStyle.merge(
98 1 : TextStyle(fontSize: 23.0),
99 : );
100 :
101 1 : return ListTile(
102 1 : key: ValueKey(
103 1 : 'pal_FontFamilyPicker_ListView_ListTile$index'),
104 1 : title: Text(
105 : key,
106 : style: modifiedFontStyle,
107 : ),
108 2 : trailing: (key == model.selectedFontFamilyKey)
109 1 : ? Icon(
110 : Icons.check,
111 1 : key: ValueKey(
112 1 : 'pal_FontFamilyPicker_ListView_ListTile_Check$index'),
113 3 : color: PalTheme.of(context).colors.dark,
114 : )
115 : : null,
116 0 : onTap: () {
117 0 : Navigator.pop(
118 : context,
119 : key,
120 : );
121 : },
122 : );
123 : },
124 : )
125 1 : : Center(
126 1 : child: CircularProgressIndicator(),
127 : ),
128 : ),
129 1 : if (!model.isLoading)
130 1 : Padding(
131 1 : key: ValueKey('pal_FontFamilyPicker_ResultsLabel'),
132 : padding: const EdgeInsets.only(bottom: 20.0, top: 20.0),
133 1 : child: Text(
134 7 : '${model.fonts.length.toString()} ${(model.fonts.length <= 1 ? 'result' : 'results')}',
135 : ),
136 : ),
137 : ],
138 : ),
139 : );
140 : }
141 : }
|