mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
SettingsUI: Allow the FontSize to be configured
This commit is contained in:
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:journal/settings.dart';
|
||||
import 'package:journal/utils.dart';
|
||||
|
||||
import 'package:preferences/preferences.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -30,6 +32,7 @@ class SettingsList extends StatefulWidget {
|
||||
class SettingsListState extends State<SettingsList> {
|
||||
final gitAuthorKey = GlobalKey<FormFieldState<String>>();
|
||||
final gitAuthorEmailKey = GlobalKey<FormFieldState<String>>();
|
||||
final fontSizeKey = GlobalKey<FormFieldState<String>>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -104,18 +107,84 @@ class SettingsListState extends State<SettingsList> {
|
||||
},
|
||||
);
|
||||
|
||||
var listView = ListView(children: <Widget>[
|
||||
SettingsHeader("Git Settings"),
|
||||
var fontSizeForm = Form(
|
||||
child: TextFormField(
|
||||
key: fontSizeKey,
|
||||
style: Theme.of(context).textTheme.title,
|
||||
decoration: const InputDecoration(
|
||||
icon: Icon(Icons.email),
|
||||
hintText: 'Who should author the changes?',
|
||||
labelText: 'Git Author Email',
|
||||
),
|
||||
validator: (String value) {
|
||||
value = value.trim();
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter an email';
|
||||
}
|
||||
|
||||
bool emailValid =
|
||||
RegExp(r"^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(value);
|
||||
if (!emailValid) {
|
||||
return 'Please enter a valid email';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: saveGitAuthorEmail,
|
||||
onSaved: saveGitAuthorEmail,
|
||||
initialValue: Settings.instance.gitAuthorEmail,
|
||||
),
|
||||
onChanged: () {
|
||||
if (!gitAuthorEmailKey.currentState.validate()) return;
|
||||
var gitAuthorEmail = gitAuthorEmailKey.currentState.value;
|
||||
saveGitAuthorEmail(gitAuthorEmail);
|
||||
},
|
||||
);
|
||||
|
||||
return PreferencePage([
|
||||
PreferenceTitle('Display Settings'),
|
||||
DropdownPreference(
|
||||
'Font Size',
|
||||
'font_size',
|
||||
defaultVal: "Normal",
|
||||
values: [
|
||||
"Extra Small",
|
||||
"Small",
|
||||
"Normal",
|
||||
"Large",
|
||||
"Extra Large",
|
||||
],
|
||||
onChange: (newVal) {
|
||||
NoteViewerFontSize fontSize;
|
||||
switch (newVal) {
|
||||
case "Extra Small":
|
||||
fontSize = NoteViewerFontSize.ExtraSmall;
|
||||
break;
|
||||
case "Small":
|
||||
fontSize = NoteViewerFontSize.Small;
|
||||
break;
|
||||
case "Normal":
|
||||
fontSize = NoteViewerFontSize.Normal;
|
||||
break;
|
||||
case "Large":
|
||||
fontSize = NoteViewerFontSize.Large;
|
||||
break;
|
||||
case "Extra Large":
|
||||
fontSize = NoteViewerFontSize.ExtraLarge;
|
||||
break;
|
||||
default:
|
||||
fontSize = NoteViewerFontSize.Normal;
|
||||
}
|
||||
Settings.instance.noteViewerFontSize = fontSize;
|
||||
Settings.instance.save();
|
||||
},
|
||||
),
|
||||
PreferenceTitle("Git Settings"),
|
||||
ListTile(title: gitAuthorForm),
|
||||
ListTile(title: gitAuthorEmailForm),
|
||||
SizedBox(height: 16.0),
|
||||
VersionNumberTile(),
|
||||
]);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: listView,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,14 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum NoteViewerFontSize { Normal, Small, ExtraSmall, Large, ExtraLarge }
|
||||
enum NoteFileNameFormat {
|
||||
Iso8601,
|
||||
Iso8601WithTimeZone,
|
||||
Iso8601WithTimeZoneWithoutColon,
|
||||
}
|
||||
|
||||
class Settings {
|
||||
static List<Function> changeObservers;
|
||||
static List<Function> changeObservers = [];
|
||||
|
||||
// singleton
|
||||
static final Settings _singleton = Settings._internal();
|
||||
@ -14,6 +19,8 @@ class Settings {
|
||||
// Properties
|
||||
String gitAuthor = "GitJournal";
|
||||
String gitAuthorEmail = "app@gitjournal.io";
|
||||
NoteFileNameFormat noteFileNameFormat =
|
||||
NoteFileNameFormat.Iso8601WithTimeZone;
|
||||
|
||||
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
||||
|
||||
@ -21,17 +28,22 @@ class Settings {
|
||||
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||
|
||||
var str =
|
||||
pref.getString("noteViewerFontSize") ?? noteViewerFontSize.toString();
|
||||
print(NoteViewerFontSize.values);
|
||||
String str;
|
||||
str = pref.getString("noteViewerFontSize") ?? noteViewerFontSize.toString();
|
||||
noteViewerFontSize =
|
||||
NoteViewerFontSize.values.firstWhere((e) => e.toString() == str);
|
||||
|
||||
str = pref.getString("noteFileNameFormat") ?? noteFileNameFormat.toString();
|
||||
noteFileNameFormat =
|
||||
NoteFileNameFormat.values.firstWhere((e) => e.toString() == str);
|
||||
}
|
||||
|
||||
Future save() async {
|
||||
var pref = await SharedPreferences.getInstance();
|
||||
pref.setString("gitAuthor", gitAuthor);
|
||||
pref.setString("gitAuthorEmail", gitAuthorEmail);
|
||||
pref.setString("noteViewerFontSize", noteViewerFontSize.toString());
|
||||
pref.setString("noteFileNameFormat", noteFileNameFormat.toString());
|
||||
|
||||
// Shouldn't we check if something has actually changed?
|
||||
for (var f in changeObservers) {
|
||||
|
31
pubspec.lock
31
pubspec.lock
@ -28,7 +28,7 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
version: "2.3.0"
|
||||
auto_size_text:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -49,7 +49,7 @@ packages:
|
||||
name: boolean_selector
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
version: "1.0.5"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -77,7 +77,7 @@ packages:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.6"
|
||||
version: "2.1.1+1"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -105,7 +105,7 @@ packages:
|
||||
name: file
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.0.8"
|
||||
version: "5.0.8+1"
|
||||
fimber:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -286,7 +286,7 @@ packages:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.6"
|
||||
version: "1.1.7"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -335,14 +335,14 @@ packages:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.2"
|
||||
version: "1.6.4"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.7.0"
|
||||
version: "1.8.0+1"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -356,7 +356,7 @@ packages:
|
||||
name: platform
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
version: "2.2.1"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -364,13 +364,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: process
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.9"
|
||||
version: "3.0.11"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -384,7 +391,7 @@ packages:
|
||||
name: quiver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "2.0.5"
|
||||
share:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -473,7 +480,7 @@ packages:
|
||||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
version: "1.0.5"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -550,7 +557,7 @@ packages:
|
||||
name: web_socket_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.13"
|
||||
version: "1.0.15"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -25,6 +25,7 @@ dependencies:
|
||||
function_types: ^0.0.2
|
||||
auto_size_text: ^2.0.1
|
||||
fimber: ^0.3.0
|
||||
preferences: ^4.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_launcher_icons: "^0.7.2"
|
||||
|
Reference in New Issue
Block a user