refactor: use google_fonts package

This commit is contained in:
Rongjian Zhang 2021-07-20 14:33:34 +08:00
parent d6a24c257a
commit d48ac1e484
30 changed files with 136 additions and 150 deletions

View File

@ -6,6 +6,8 @@ PODS:
- Flutter - Flutter
- package_info_plus (0.4.5): - package_info_plus (0.4.5):
- Flutter - Flutter
- path_provider (0.0.1):
- Flutter
- Sentry (7.1.3): - Sentry (7.1.3):
- Sentry/Core (= 7.1.3) - Sentry/Core (= 7.1.3)
- Sentry/Core (7.1.3) - Sentry/Core (7.1.3)
@ -29,6 +31,7 @@ DEPENDENCIES:
- launch_review (from `.symlinks/plugins/launch_review/ios`) - launch_review (from `.symlinks/plugins/launch_review/ios`)
- package_info (from `.symlinks/plugins/package_info/ios`) - package_info (from `.symlinks/plugins/package_info/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`) - sentry_flutter (from `.symlinks/plugins/sentry_flutter/ios`)
- share (from `.symlinks/plugins/share/ios`) - share (from `.symlinks/plugins/share/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
@ -49,6 +52,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/package_info/ios" :path: ".symlinks/plugins/package_info/ios"
package_info_plus: package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios" :path: ".symlinks/plugins/package_info_plus/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
sentry_flutter: sentry_flutter:
:path: ".symlinks/plugins/sentry_flutter/ios" :path: ".symlinks/plugins/sentry_flutter/ios"
share: share:
@ -67,6 +72,7 @@ SPEC CHECKSUMS:
launch_review: 75d5a956ba8eaa493e9c9d4bf4c05e505e8d5ed0 launch_review: 75d5a956ba8eaa493e9c9d4bf4c05e505e8d5ed0
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62 package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
Sentry: 6d963d64804dd06d96e778be729613f481394312 Sentry: 6d963d64804dd06d96e778be729613f481394312
sentry_flutter: f20d4f199442900fbdab2b8496f1d2091d8b94d9 sentry_flutter: f20d4f199442900fbdab2b8496f1d2091d8b94d9
share: 0b2c3e82132f5888bccca3351c504d0003b3b410 share: 0b2c3e82132f5888bccca3351c504d0003b3b410

View File

@ -5,6 +5,7 @@ import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:git_touch/router.dart'; import 'package:git_touch/router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:git_touch/models/notification.dart'; import 'package:git_touch/models/notification.dart';
import 'package:fluro/fluro.dart'; import 'package:fluro/fluro.dart';
@ -19,6 +20,8 @@ void main() async {
}, },
// Init your App. // Init your App.
appRunner: () async { appRunner: () async {
GoogleFonts.config.allowRuntimeFetching = false;
final notificationModel = NotificationModel(); final notificationModel = NotificationModel();
final themeModel = ThemeModel(); final themeModel = ThemeModel();
final authModel = AuthModel(); final authModel = AuthModel();

View File

@ -1,7 +1,9 @@
import 'package:fimber/fimber.dart'; import 'package:fimber/fimber.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_highlight/theme_map.dart'; import 'package:flutter_highlight/theme_map.dart';
import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/utils/utils.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class CodeModel with ChangeNotifier { class CodeModel with ChangeNotifier {
@ -15,7 +17,7 @@ class CodeModel with ChangeNotifier {
'PT Mono', 'PT Mono',
'Source Code Pro', 'Source Code Pro',
'Ubuntu Mono', 'Ubuntu Mono',
'Cascadia Code', // 'Cascadia Code', // TODO: https://github.com/google/fonts/issues/2179
]; ];
String _theme = 'vs'; String _theme = 'vs';
@ -25,10 +27,17 @@ class CodeModel with ChangeNotifier {
String get theme => _theme; String get theme => _theme;
String get themeDark => _themeDark; String get themeDark => _themeDark;
int get fontSize => _fontSize; int get fontSize => _fontSize;
String get fontFamily => _fontFamily; String get fontFamily => _fontFamily;
String get fontFamilyUsed => TextStyle get fontStyle {
_fontFamily == 'System' ? CommonStyle.monospace : _fontFamily; if (_fontFamily == 'System') {
return TextStyle(
fontFamily: CommonStyle.monospace, fontSize: fontSize.toDouble());
} else {
return GoogleFonts.getFont(_fontFamily, fontSize: fontSize.toDouble());
}
}
Future<void> init() async { Future<void> init() async {
var prefs = await SharedPreferences.getInstance(); var prefs = await SharedPreferences.getInstance();

View File

@ -133,20 +133,14 @@ class MyApp extends StatelessWidget {
_getCode(false), _getCode(false),
language: 'dart', language: 'dart',
theme: themeMap[codeProvider.theme]!, theme: themeMap[codeProvider.theme]!,
textStyle: TextStyle( textStyle: codeProvider.fontStyle,
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed,
),
padding: CommonStyle.padding, padding: CommonStyle.padding,
), ),
HighlightView( HighlightView(
_getCode(true), _getCode(true),
language: 'dart', language: 'dart',
theme: themeMap[codeProvider.themeDark]!, theme: themeMap[codeProvider.themeDark]!,
textStyle: TextStyle( textStyle: codeProvider.fontStyle,
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed,
),
padding: CommonStyle.padding, padding: CommonStyle.padding,
), ),
], ],

View File

@ -46,9 +46,7 @@ class GlCommitScreen extends StatelessWidget {
? codeProvider.themeDark ? codeProvider.themeDark
: codeProvider.theme]!, : codeProvider.theme]!,
padding: CommonStyle.padding, padding: CommonStyle.padding,
textStyle: TextStyle( textStyle: codeProvider.fontStyle,
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed),
), ),
), ),
], ],

View File

@ -62,9 +62,7 @@ class BlobView extends StatelessWidget {
? codeProvider.themeDark ? codeProvider.themeDark
: codeProvider.theme]!, : codeProvider.theme]!,
padding: CommonStyle.padding, padding: CommonStyle.padding,
textStyle: TextStyle( textStyle: codeProvider.fontStyle,
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed),
), ),
); );
} }

View File

@ -1,86 +1,86 @@
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:git_touch/models/code.dart'; // import 'package:git_touch/models/code.dart';
import 'package:git_touch/models/theme.dart'; // import 'package:git_touch/models/theme.dart';
import 'package:provider/provider.dart'; // import 'package:provider/provider.dart';
class DiffLine { // class DiffLine {
String? type; // String? type;
int lineNumber; // int lineNumber;
String content; // String content;
DiffLine({ // DiffLine({
required this.type, // required this.type,
required this.lineNumber, // required this.lineNumber,
required this.content, // required this.content,
}); // });
} // }
class DiffChunk { // class DiffChunk {
String heading; // String heading;
List<DiffLine> lines; // List<DiffLine> lines;
DiffChunk({required this.heading, required this.lines}); // DiffChunk({required this.heading, required this.lines});
} // }
class DiffView extends StatelessWidget { // class DiffView extends StatelessWidget {
final String source; // final String source;
DiffView(this.source); // DiffView(this.source);
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
final code = Provider.of<CodeModel>(context); // final code = Provider.of<CodeModel>(context);
final theme = Provider.of<ThemeModel>(context); // final theme = Provider.of<ThemeModel>(context);
final lines = source.split('\n'); // final lines = source.split('\n');
final chunks = <DiffChunk>[]; // final chunks = <DiffChunk>[];
var offset = 0; // var offset = 0;
for (final line in lines) { // for (final line in lines) {
if (line.startsWith('@@')) { // if (line.startsWith('@@')) {
chunks.add(DiffChunk(heading: line, lines: [])); // chunks.add(DiffChunk(heading: line, lines: []));
offset = int.parse(line.substring(4).split(',')[0]); // offset = int.parse(line.substring(4).split(',')[0]);
} else { // } else {
chunks.last.lines.add(DiffLine( // chunks.last.lines.add(DiffLine(
type: line.isEmpty ? null : line[0], // type: line.isEmpty ? null : line[0],
lineNumber: offset, // lineNumber: offset,
content: line, // content: line,
)); // ));
offset++; // offset++;
} // }
} // }
return DefaultTextStyle( // return DefaultTextStyle(
child: Column( // child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
for (var c in chunks) // for (var c in chunks)
Column( // Column(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
Text( // Text(
c.heading, // c.heading,
style: TextStyle( // style: TextStyle(
color: theme.palette.tertiaryText, // color: theme.palette.tertiaryText,
backgroundColor: Color(0xfffafafa), // backgroundColor: Color(0xfffafafa),
), // ),
), // ),
for (var l in c.lines) // for (var l in c.lines)
Text( // Text(
l.content, // l.content,
style: TextStyle( // style: TextStyle(
backgroundColor: l.type == '-' // backgroundColor: l.type == '-'
? Color(0x00fbe9eb) // ? Color(0x00fbe9eb)
: l.type == '+' // : l.type == '+'
? Color(0xffecfdf0) // ? Color(0xffecfdf0)
: null, // : null,
), // ),
), // ),
], // ],
), // ),
], // ],
), // ),
style: TextStyle( // style: TextStyle(
fontFamily: code.fontFamilyUsed, // fontFamily: code.fontFamilyUsed,
fontSize: 14, // fontSize: 14,
color: theme.palette.text, // color: theme.palette.text,
), // ),
); // );
} // }
} // }

View File

@ -47,9 +47,7 @@ class FilesItem extends StatelessWidget {
theme: themeMap[theme.brightness == Brightness.dark theme: themeMap[theme.brightness == Brightness.dark
? codeProvider.themeDark ? codeProvider.themeDark
: codeProvider.theme]!, : codeProvider.theme]!,
textStyle: TextStyle( textStyle: codeProvider.fontStyle,
fontSize: codeProvider.fontSize.toDouble(),
fontFamily: codeProvider.fontFamilyUsed),
), ),
), ),
], ],

View File

@ -164,7 +164,7 @@ class MarkdownFlutterView extends StatelessWidget {
backgroundColor: theme.palette.grayBackground, backgroundColor: theme.palette.grayBackground,
fontSize: 16 * 0.85, fontSize: 16 * 0.85,
height: 1.45, height: 1.45,
fontFamily: code.fontFamilyUsed, fontFamily: code.fontStyle.fontFamily,
), ),
h1: _hStyle.copyWith(fontSize: 32), h1: _hStyle.copyWith(fontSize: 32),
h2: _hStyle.copyWith(fontSize: 24), h2: _hStyle.copyWith(fontSize: 24),

View File

@ -5,14 +5,18 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import in_app_review
import package_info import package_info
import package_info_plus_macos
import path_provider_macos
import sentry_flutter
import shared_preferences_macos import shared_preferences_macos
import url_launcher_macos import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
InAppReviewPlugin.register(with: registry.registrar(forPlugin: "InAppReviewPlugin"))
FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin")) FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
} }

View File

@ -350,6 +350,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
google_fonts:
dependency: "direct main"
description:
name: google_fonts
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
gql: gql:
dependency: transitive dependency: transitive
description: description:
@ -609,6 +616,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.1" version: "0.2.1"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -616,6 +630,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
path_provider_platform_interface: path_provider_platform_interface:
dependency: transitive dependency: transitive
description: description:

View File

@ -52,6 +52,7 @@ dependencies:
webview_flutter: ^2.0.4 webview_flutter: ^2.0.4
sentry_flutter: ^5.1.0 sentry_flutter: ^5.1.0
pub_semver: ^2.0.0 pub_semver: ^2.0.0
google_fonts:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -71,52 +72,6 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- images/ - images/
fonts: - google_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
- family: Cascadia Code
fonts:
- asset: fonts/Cascadia.ttf
- family: JetBrains Mono
fonts:
- asset: fonts/JetBrainsMono-Regular.ttf
- asset: fonts/JetBrainsMono-Italic.ttf
style: italic
- asset: fonts/JetBrainsMono-Bold.ttf
weight: 700
- asset: fonts/JetBrainsMono-Bold-Italic.ttf
style: italic
weight: 700
flutter_intl: flutter_intl:
enabled: true enabled: true