mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 03:19:11 +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/settings.dart';
|
||||||
import 'package:journal/utils.dart';
|
import 'package:journal/utils.dart';
|
||||||
|
|
||||||
|
import 'package:preferences/preferences.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatelessWidget {
|
class SettingsScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -30,6 +32,7 @@ class SettingsList extends StatefulWidget {
|
|||||||
class SettingsListState extends State<SettingsList> {
|
class SettingsListState extends State<SettingsList> {
|
||||||
final gitAuthorKey = GlobalKey<FormFieldState<String>>();
|
final gitAuthorKey = GlobalKey<FormFieldState<String>>();
|
||||||
final gitAuthorEmailKey = GlobalKey<FormFieldState<String>>();
|
final gitAuthorEmailKey = GlobalKey<FormFieldState<String>>();
|
||||||
|
final fontSizeKey = GlobalKey<FormFieldState<String>>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -104,18 +107,84 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
var listView = ListView(children: <Widget>[
|
var fontSizeForm = Form(
|
||||||
SettingsHeader("Git Settings"),
|
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: gitAuthorForm),
|
||||||
ListTile(title: gitAuthorEmailForm),
|
ListTile(title: gitAuthorEmailForm),
|
||||||
SizedBox(height: 16.0),
|
SizedBox(height: 16.0),
|
||||||
VersionNumberTile(),
|
VersionNumberTile(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: listView,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
enum NoteViewerFontSize { Normal, Small, ExtraSmall, Large, ExtraLarge }
|
enum NoteViewerFontSize { Normal, Small, ExtraSmall, Large, ExtraLarge }
|
||||||
|
enum NoteFileNameFormat {
|
||||||
|
Iso8601,
|
||||||
|
Iso8601WithTimeZone,
|
||||||
|
Iso8601WithTimeZoneWithoutColon,
|
||||||
|
}
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
static List<Function> changeObservers;
|
static List<Function> changeObservers = [];
|
||||||
|
|
||||||
// singleton
|
// singleton
|
||||||
static final Settings _singleton = Settings._internal();
|
static final Settings _singleton = Settings._internal();
|
||||||
@ -14,6 +19,8 @@ class Settings {
|
|||||||
// Properties
|
// Properties
|
||||||
String gitAuthor = "GitJournal";
|
String gitAuthor = "GitJournal";
|
||||||
String gitAuthorEmail = "app@gitjournal.io";
|
String gitAuthorEmail = "app@gitjournal.io";
|
||||||
|
NoteFileNameFormat noteFileNameFormat =
|
||||||
|
NoteFileNameFormat.Iso8601WithTimeZone;
|
||||||
|
|
||||||
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
NoteViewerFontSize noteViewerFontSize = NoteViewerFontSize.Normal;
|
||||||
|
|
||||||
@ -21,17 +28,22 @@ class Settings {
|
|||||||
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
gitAuthor = pref.getString("gitAuthor") ?? gitAuthor;
|
||||||
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
gitAuthorEmail = pref.getString("gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
|
|
||||||
var str =
|
String str;
|
||||||
pref.getString("noteViewerFontSize") ?? noteViewerFontSize.toString();
|
str = pref.getString("noteViewerFontSize") ?? noteViewerFontSize.toString();
|
||||||
print(NoteViewerFontSize.values);
|
|
||||||
noteViewerFontSize =
|
noteViewerFontSize =
|
||||||
NoteViewerFontSize.values.firstWhere((e) => e.toString() == str);
|
NoteViewerFontSize.values.firstWhere((e) => e.toString() == str);
|
||||||
|
|
||||||
|
str = pref.getString("noteFileNameFormat") ?? noteFileNameFormat.toString();
|
||||||
|
noteFileNameFormat =
|
||||||
|
NoteFileNameFormat.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);
|
||||||
|
pref.setString("noteViewerFontSize", noteViewerFontSize.toString());
|
||||||
|
pref.setString("noteFileNameFormat", noteFileNameFormat.toString());
|
||||||
|
|
||||||
// Shouldn't we check if something has actually changed?
|
// Shouldn't we check if something has actually changed?
|
||||||
for (var f in changeObservers) {
|
for (var f in changeObservers) {
|
||||||
|
31
pubspec.lock
31
pubspec.lock
@ -28,7 +28,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.0"
|
version: "2.3.0"
|
||||||
auto_size_text:
|
auto_size_text:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -49,7 +49,7 @@ packages:
|
|||||||
name: boolean_selector
|
name: boolean_selector
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.5"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -77,7 +77,7 @@ packages:
|
|||||||
name: crypto
|
name: crypto
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.6"
|
version: "2.1.1+1"
|
||||||
csslib:
|
csslib:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -105,7 +105,7 @@ packages:
|
|||||||
name: file
|
name: file
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.8"
|
version: "5.0.8+1"
|
||||||
fimber:
|
fimber:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -286,7 +286,7 @@ packages:
|
|||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.6"
|
version: "1.1.7"
|
||||||
mime:
|
mime:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -335,14 +335,14 @@ packages:
|
|||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.2"
|
version: "1.6.4"
|
||||||
pedantic:
|
pedantic:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: pedantic
|
name: pedantic
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
version: "1.8.0+1"
|
||||||
petitparser:
|
petitparser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -356,7 +356,7 @@ packages:
|
|||||||
name: platform
|
name: platform
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.0"
|
version: "2.2.1"
|
||||||
pool:
|
pool:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -364,13 +364,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "1.4.0"
|
||||||
|
preferences:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: preferences
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.0"
|
||||||
process:
|
process:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: process
|
name: process
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.9"
|
version: "3.0.11"
|
||||||
pub_semver:
|
pub_semver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -384,7 +391,7 @@ packages:
|
|||||||
name: quiver
|
name: quiver
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "2.0.5"
|
||||||
share:
|
share:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -473,7 +480,7 @@ packages:
|
|||||||
name: string_scanner
|
name: string_scanner
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.5"
|
||||||
term_glyph:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -550,7 +557,7 @@ packages:
|
|||||||
name: web_socket_channel
|
name: web_socket_channel
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.13"
|
version: "1.0.15"
|
||||||
xml:
|
xml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -25,6 +25,7 @@ dependencies:
|
|||||||
function_types: ^0.0.2
|
function_types: ^0.0.2
|
||||||
auto_size_text: ^2.0.1
|
auto_size_text: ^2.0.1
|
||||||
fimber: ^0.3.0
|
fimber: ^0.3.0
|
||||||
|
preferences: ^4.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user