feat: add popular monospace fonts

This commit is contained in:
Rongjian Zhang 2019-09-15 18:27:46 +08:00
parent a47d84a6cc
commit 7a9fb0ffee
17 changed files with 63 additions and 4 deletions

BIN
fonts/FiraCode-Bold.ttf Normal file

Binary file not shown.

BIN
fonts/FiraCode-Regular.ttf Normal file

Binary file not shown.

BIN
fonts/Inconsolata-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

BIN
fonts/PTMono-Regular.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
fonts/UbuntuMono-Bold.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_highlight/theme_map.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:shared_preferences/shared_preferences.dart';
class CodeModel with ChangeNotifier {
@ -9,7 +10,14 @@ class CodeModel with ChangeNotifier {
static var themes = themeMap.keys.toList();
static const fontSizes = [12, 13, 14, 15, 16, 17, 18, 19, 20];
static const fontFamilies = ['System'];
static const fontFamilies = [
'System',
'Fira Code',
'Inconsolata',
'PT Mono',
'Source Code Pro',
'Ubuntu Mono'
];
String _theme = 'github';
int _fontSize = 14;
@ -18,6 +26,8 @@ class CodeModel with ChangeNotifier {
String get theme => _theme;
int get fontSize => _fontSize;
String get fontFamily => _fontFamily;
String get fontFamilyUsed =>
_fontFamily == 'System' ? monospaceFont : _fontFamily;
init() async {
var prefs = await SharedPreferences.getInstance();

View File

@ -79,7 +79,22 @@ class CodeSettingsScreen extends StatelessWidget {
text: Text('Font Family'),
rightWidget: Text(codeProvider.fontFamily.toString()),
onTap: () {
// TODO:
Provider.of<ThemeModel>(context).showPicker(
context,
children:
CodeModel.fontFamilies.map((k) => Text(k)).toList(),
initialItem: CodeModel.fontFamilies
.indexOf(codeProvider.fontFamily),
onSelectedItemChanged: (int value) {
if (_themeDebounce?.isActive ?? false)
_themeDebounce.cancel();
_themeDebounce =
Timer(const Duration(milliseconds: 500), () {
Provider.of<CodeModel>(context)
.setFontFamily(CodeModel.fontFamilies[value]);
});
},
);
},
),
],
@ -92,7 +107,7 @@ class CodeSettingsScreen extends StatelessWidget {
theme: themeMap[codeProvider.theme],
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: monospaceFont,
fontFamily: codeProvider.fontFamilyUsed,
),
padding: const EdgeInsets.all(10),
),

View File

@ -135,7 +135,7 @@ class ObjectScreen extends StatelessWidget {
padding: EdgeInsets.all(10),
textStyle: TextStyle(
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: monospaceFont),
fontFamily: codeProvider.fontFamilyUsed),
),
);
}

View File

@ -58,3 +58,37 @@ flutter:
uses-material-design: true
assets:
- images/
fonts:
- family: Fira Code
fonts:
- asset: fonts/FiraCode-Regular.ttf
- asset: fonts/FiraCode-Bold.ttf
weight: 700
- family: Inconsolata
fonts:
- asset: fonts/Inconsolata-Regular.ttf
- asset: fonts/Inconsolata-Bold.ttf
weight: 700
- family: PT Mono
fonts:
- asset: fonts/PTMono-Regular.ttf
- family: Source Code Pro
fonts:
- asset: fonts/SourceCodePro-Regular.ttf
- asset: fonts/SourceCodePro-RegularItalic.ttf
style: italic
- asset: fonts/SourceCodePro-Bold.ttf
weight: 700
- asset: fonts/SourceCodePro-BoldItalic.ttf
style: italic
weight: 700
- family: Ubuntu Mono
fonts:
- asset: fonts/UbuntuMono-Regular.ttf
- asset: fonts/UbuntuMono-RegularItalic.ttf
style: italic
- asset: fonts/UbuntuMono-Bold.ttf
weight: 700
- asset: fonts/UbuntuMono-BoldItalic.ttf
style: italic
weight: 700