-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathcode_theme.dart
More file actions
154 lines (150 loc) · 5.2 KB
/
code_theme.dart
File metadata and controls
154 lines (150 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import 'package:antd_mobile/antd_mobile.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/single.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:provider/provider.dart';
class CodeThemeScreen extends StatelessWidget {
String _getCode(bool isDark) => '''// ${isDark ? 'Dark' : 'Light'} Mode
import 'package:flutter/widgets.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Hello World'),
),
),
);
}
}
''';
@override
Widget build(BuildContext context) {
final codeProvider = Provider.of<CodeModel>(context);
final theme = Provider.of<ThemeModel>(context);
return SingleScaffold(
title: Text(AppLocalizations.of(context)!.codeTheme),
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
CommonStyle.verticalGap,
AntList(
mode: AntListMode.card,
header: Text(AppLocalizations.of(context)!.fontStyle),
children: [
AntListItem(
extra: Text(codeProvider.fontSize.toString()),
onClick: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.fontSize.toString(),
items: CodeModel.fontSizes
.map((v) =>
PickerItem(v.toString(), text: v.toString()))
.toList(),
onChange: (value) {
codeProvider.setFontSize(int.tryParse(value!) ?? 16);
},
),
);
},
child: Text(AppLocalizations.of(context)!.fontSize),
),
AntListItem(
extra: Text(codeProvider.fontFamily),
onClick: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.fontFamily,
items: CodeModel.fontFamilies
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (value) {
codeProvider.setFontFamily(value!);
},
),
);
},
child: Text(AppLocalizations.of(context)!.fontFamily),
),
],
),
CommonStyle.verticalGap,
AntList(
mode: AntListMode.card,
header: Text(AppLocalizations.of(context)!.syntaxHighlighting),
children: [
AntListItem(
extra: Text(codeProvider.theme),
onClick: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.theme,
items: CodeModel.themes
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (value) {
codeProvider.setTheme(value!);
},
),
);
},
child: Text(AppLocalizations.of(context)!.light),
),
AntListItem(
child: HighlightView(
_getCode(true),
language: 'dart',
theme: themeMap[codeProvider.theme]!,
textStyle: codeProvider.fontStyle,
padding: CommonStyle.padding,
),
),
AntListItem(
extra: Text(codeProvider.themeDark),
onClick: () {
theme.showPicker(
context,
PickerGroupItem(
value: codeProvider.themeDark,
items: CodeModel.themes
.map((v) => PickerItem(v, text: v))
.toList(),
onChange: (value) {
codeProvider.setThemeDark(value!);
},
),
);
},
child: Text(AppLocalizations.of(context)!.dark),
),
AntListItem(
child: HighlightView(
_getCode(true),
language: 'dart',
theme: themeMap[codeProvider.themeDark]!,
textStyle: codeProvider.fontStyle,
padding: CommonStyle.padding,
),
)
],
),
],
),
);
}
}