mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-15 07:56:11 +08:00

For now I've mostly tried to follow the same style guide as the flutter repository, with many options disabled. Eventually, maybe it would make sense to be far stricter.
189 lines
4.9 KiB
Dart
189 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:journal/app.dart';
|
|
import 'package:journal/settings.dart';
|
|
import 'package:package_info/package_info.dart';
|
|
|
|
class SettingsScreen extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Settings'),
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
),
|
|
body: SettingsList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SettingsList extends StatefulWidget {
|
|
@override
|
|
SettingsListState createState() {
|
|
return SettingsListState();
|
|
}
|
|
}
|
|
|
|
class SettingsListState extends State<SettingsList> {
|
|
final gitAuthorKey = GlobalKey<FormFieldState<String>>();
|
|
final gitAuthorEmailKey = GlobalKey<FormFieldState<String>>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var gitAuthorForm = Form(
|
|
child: TextFormField(
|
|
key: gitAuthorKey,
|
|
style: Theme.of(context).textTheme.title,
|
|
decoration: const InputDecoration(
|
|
icon: Icon(Icons.person),
|
|
hintText: 'Who should author the changes?',
|
|
labelText: 'Git Author',
|
|
),
|
|
validator: (String value) {
|
|
value = value.trim();
|
|
if (value.isEmpty) {
|
|
return 'Please enter a name';
|
|
}
|
|
},
|
|
textInputAction: TextInputAction.done,
|
|
onFieldSubmitted: (String gitAuthor) {
|
|
Settings.instance.gitAuthor = gitAuthor;
|
|
Settings.instance.save();
|
|
},
|
|
onSaved: (String gitAuthor) {
|
|
Settings.instance.gitAuthor = gitAuthor;
|
|
Settings.instance.save();
|
|
},
|
|
initialValue: Settings.instance.gitAuthor,
|
|
),
|
|
onChanged: () {
|
|
if (!gitAuthorKey.currentState.validate()) return;
|
|
var gitAuthor = gitAuthorKey.currentState.value;
|
|
Settings.instance.gitAuthor = gitAuthor;
|
|
Settings.instance.save();
|
|
},
|
|
);
|
|
|
|
var gitAuthorEmailForm = Form(
|
|
child: TextFormField(
|
|
key: gitAuthorEmailKey,
|
|
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';
|
|
}
|
|
},
|
|
textInputAction: TextInputAction.done,
|
|
onFieldSubmitted: (String gitAuthorEmail) {
|
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
|
Settings.instance.save();
|
|
},
|
|
onSaved: (String gitAuthorEmail) {
|
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
|
Settings.instance.save();
|
|
},
|
|
initialValue: Settings.instance.gitAuthorEmail,
|
|
),
|
|
onChanged: () {
|
|
if (!gitAuthorEmailKey.currentState.validate()) return;
|
|
var gitAuthorEmail = gitAuthorEmailKey.currentState.value;
|
|
Settings.instance.gitAuthorEmail = gitAuthorEmail;
|
|
Settings.instance.save();
|
|
},
|
|
);
|
|
|
|
var listView = ListView(children: <Widget>[
|
|
SettingsHeader("Git Settings"),
|
|
ListTile(title: gitAuthorForm),
|
|
ListTile(title: gitAuthorEmailForm),
|
|
SettingsHeader("Version Info"),
|
|
VersionNumberTile(),
|
|
]);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: listView,
|
|
);
|
|
}
|
|
}
|
|
|
|
class SettingsHeader extends StatelessWidget {
|
|
final String text;
|
|
SettingsHeader(this.text);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListTile(
|
|
title: Text(
|
|
text,
|
|
style: Theme.of(context).textTheme.headline,
|
|
),
|
|
enabled: false,
|
|
);
|
|
}
|
|
}
|
|
|
|
class VersionNumberTile extends StatefulWidget {
|
|
@override
|
|
VersionNumberTileState createState() {
|
|
return VersionNumberTileState();
|
|
}
|
|
}
|
|
|
|
class VersionNumberTileState extends State<VersionNumberTile> {
|
|
PackageInfo packageInfo;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
() async {
|
|
PackageInfo info = await PackageInfo.fromPlatform();
|
|
setState(() {
|
|
packageInfo = info;
|
|
});
|
|
}();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var text = "";
|
|
if (packageInfo != null) {
|
|
text = packageInfo.appName +
|
|
" " +
|
|
packageInfo.version +
|
|
"+" +
|
|
packageInfo.buildNumber;
|
|
|
|
if (JournalApp.isInDebugMode) {
|
|
text += " (Debug)";
|
|
}
|
|
}
|
|
|
|
return ListTile(
|
|
title: Text(
|
|
text,
|
|
style: Theme.of(context).textTheme.subhead,
|
|
textAlign: TextAlign.left,
|
|
),
|
|
onTap: () {},
|
|
);
|
|
}
|
|
}
|