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
- package_info_plus (0.4.5):
- Flutter
- path_provider (0.0.1):
- Flutter
- Sentry (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`)
- package_info (from `.symlinks/plugins/package_info/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`)
- share (from `.symlinks/plugins/share/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
@ -49,6 +52,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/package_info/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
sentry_flutter:
:path: ".symlinks/plugins/sentry_flutter/ios"
share:
@ -67,6 +72,7 @@ SPEC CHECKSUMS:
launch_review: 75d5a956ba8eaa493e9c9d4bf4c05e505e8d5ed0
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
Sentry: 6d963d64804dd06d96e778be729613f481394312
sentry_flutter: f20d4f199442900fbdab2b8496f1d2091d8b94d9
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/theme.dart';
import 'package:git_touch/router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/notification.dart';
import 'package:fluro/fluro.dart';
@ -19,6 +20,8 @@ void main() async {
},
// Init your App.
appRunner: () async {
GoogleFonts.config.allowRuntimeFetching = false;
final notificationModel = NotificationModel();
final themeModel = ThemeModel();
final authModel = AuthModel();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,14 +5,18 @@
import FlutterMacOS
import Foundation
import in_app_review
import package_info
import package_info_plus_macos
import path_provider_macos
import sentry_flutter
import shared_preferences_macos
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
InAppReviewPlugin.register(with: registry.registrar(forPlugin: "InAppReviewPlugin"))
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"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

View File

@ -350,6 +350,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:
@ -609,6 +616,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:
@ -616,6 +630,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
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:
dependency: transitive
description:

View File

@ -52,6 +52,7 @@ dependencies:
webview_flutter: ^2.0.4
sentry_flutter: ^5.1.0
pub_semver: ^2.0.0
google_fonts:
dev_dependencies:
flutter_test:
@ -71,52 +72,6 @@ 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
- 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
- google_fonts/
flutter_intl:
enabled: true