mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Settings: Allow the fontSize of the viewer to be changed
No ui has been created for this so far.
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:flutter_markdown/flutter_markdown.dart';
|
|||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import 'package:journal/state_container.dart';
|
import 'package:journal/state_container.dart';
|
||||||
import 'package:journal/utils.dart';
|
import 'package:journal/utils.dart';
|
||||||
|
import 'package:journal/settings.dart';
|
||||||
import 'package:journal/widgets/note_header.dart';
|
import 'package:journal/widgets/note_header.dart';
|
||||||
import 'package:share/share.dart';
|
import 'package:share/share.dart';
|
||||||
|
|
||||||
@ -133,7 +134,8 @@ class NoteViewer extends StatelessWidget {
|
|||||||
ThemeData theme = Theme.of(context);
|
ThemeData theme = Theme.of(context);
|
||||||
theme = theme.copyWith(
|
theme = theme.copyWith(
|
||||||
textTheme: theme.textTheme.copyWith(
|
textTheme: theme.textTheme.copyWith(
|
||||||
body1: theme.textTheme.body1.copyWith(fontSize: 18.0),
|
body1: theme.textTheme.body1
|
||||||
|
.copyWith(fontSize: Settings.instance.getNoteViewerFontSize()),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,23 +1,60 @@
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
enum NoteViewerFontSize { Normal, Small, ExtraSmall, Large, ExtraLarge }
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
|
static List<Function> changeObservers;
|
||||||
|
|
||||||
// singleton
|
// singleton
|
||||||
static final Settings _singleton = Settings._internal();
|
static final Settings _singleton = Settings._internal();
|
||||||
factory Settings() => _singleton;
|
factory Settings() => _singleton;
|
||||||
Settings._internal();
|
Settings._internal();
|
||||||
static Settings get instance => _singleton;
|
static Settings get instance => _singleton;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
String gitAuthor = "GitJournal";
|
||||||
|
String gitAuthorEmail = "app@gitjournal.io";
|
||||||
|
|
||||||
|
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
||||||
|
|
||||||
void load(SharedPreferences pref) {
|
void load(SharedPreferences pref) {
|
||||||
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||||
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
|
|
||||||
|
var str =
|
||||||
|
pref.getString("noteViewerFontSize") ?? noteViewerFontSize.toString();
|
||||||
|
print(NoteViewerFontSize.values);
|
||||||
|
noteViewerFontSize =
|
||||||
|
NoteViewerFontSize.values.firstWhere((e) => e.toString() == str);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future save() async {
|
Future save() async {
|
||||||
var pref = await SharedPreferences.getInstance();
|
var pref = await SharedPreferences.getInstance();
|
||||||
pref.setString("gitAuthor", gitAuthor);
|
pref.setString("gitAuthor", gitAuthor);
|
||||||
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
||||||
|
|
||||||
|
// Shouldn't we check if something has actually changed?
|
||||||
|
for (var f in changeObservers) {
|
||||||
|
f();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String gitAuthor = "GitJournal";
|
double getNoteViewerFontSize() {
|
||||||
String gitAuthorEmail = "app@gitjournal.io";
|
switch (noteViewerFontSize) {
|
||||||
|
case NoteViewerFontSize.Normal:
|
||||||
|
return 18.0;
|
||||||
|
case NoteViewerFontSize.Small:
|
||||||
|
return 15.0;
|
||||||
|
case NoteViewerFontSize.ExtraSmall:
|
||||||
|
return 12.0;
|
||||||
|
case NoteViewerFontSize.Large:
|
||||||
|
return 22.0;
|
||||||
|
case NoteViewerFontSize.ExtraLarge:
|
||||||
|
return 26.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(false, "getNoteViewerFontSize: We should never be here");
|
||||||
|
return 50000.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user