Skip to content

Commit e0afa27

Browse files
committed
Expose Git Remote Settings
This way you can regenerate the SSH Key (if needed) and/or copy it again. In the future one can add methods to reconfigure the git remote and add / remove remotes.
1 parent 599c6b4 commit e0afa27

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

lib/screens/settings_git_remote.dart

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import 'dart:io';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter/services.dart';
5+
import 'package:fimber/fimber.dart';
6+
7+
import 'package:git_bindings/git_bindings.dart';
8+
import 'package:gitjournal/screens/githostsetup_sshkey.dart';
9+
import 'package:gitjournal/utils.dart';
10+
11+
class GitRemoteSettingsScreen extends StatefulWidget {
12+
@override
13+
_GitRemoteSettingsScreenState createState() =>
14+
_GitRemoteSettingsScreenState();
15+
}
16+
17+
class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
18+
String publicKey = "";
19+
20+
@override
21+
void initState() {
22+
super.initState();
23+
getSSHPublicKey().then((String val) {
24+
setState(() {
25+
publicKey = val;
26+
});
27+
});
28+
}
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
var textTheme = Theme.of(context).textTheme;
33+
34+
var body = Column(
35+
children: <Widget>[
36+
Text(
37+
"SSH Public Key -",
38+
style: textTheme.body2,
39+
textAlign: TextAlign.left,
40+
),
41+
const SizedBox(height: 16.0),
42+
PublicKeyWidget(publicKey),
43+
const SizedBox(height: 16.0),
44+
const Divider(),
45+
Button(
46+
text: "Copy Key",
47+
onPressed: () => _copyKeyToClipboard(context),
48+
),
49+
Button(
50+
text: "Regnerate Key",
51+
onPressed: () => _generateSshKey(context),
52+
),
53+
],
54+
crossAxisAlignment: CrossAxisAlignment.start,
55+
);
56+
57+
return Scaffold(
58+
appBar: AppBar(
59+
title: const Text('Git Remote Settings'),
60+
leading: IconButton(
61+
icon: const Icon(Icons.arrow_back),
62+
onPressed: () {
63+
Navigator.of(context).pop();
64+
},
65+
),
66+
),
67+
body: Padding(
68+
padding: const EdgeInsets.all(16.0),
69+
child: body,
70+
),
71+
);
72+
}
73+
74+
void _copyKeyToClipboard(BuildContext context) {
75+
Clipboard.setData(ClipboardData(text: publicKey));
76+
showSnackbar(context, "Public Key copied to Clipboard");
77+
}
78+
79+
void _generateSshKey(BuildContext context) {
80+
var comment = "GitJournal " +
81+
Platform.operatingSystem +
82+
" " +
83+
DateTime.now().toIso8601String().substring(0, 10); // only the date
84+
85+
generateSSHKeys(comment: comment).then((String publicKey) {
86+
setState(() {
87+
this.publicKey = publicKey;
88+
Fimber.d("PublicKey: " + publicKey);
89+
_copyKeyToClipboard(context);
90+
});
91+
});
92+
}
93+
}
94+
95+
class Button extends StatelessWidget {
96+
final String text;
97+
final Function onPressed;
98+
99+
Button({@required this.text, @required this.onPressed});
100+
101+
@override
102+
Widget build(BuildContext context) {
103+
return SizedBox(
104+
width: double.infinity,
105+
child: RaisedButton(
106+
child: Text(
107+
text,
108+
textAlign: TextAlign.center,
109+
style: Theme.of(context).textTheme.button,
110+
),
111+
color: Theme.of(context).primaryColor,
112+
onPressed: onPressed,
113+
),
114+
);
115+
}
116+
}

lib/screens/settings_screen.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:gitjournal/settings.dart';
33
import 'package:gitjournal/utils.dart';
44
import 'package:gitjournal/screens/settings_widgets.dart';
5+
import 'package:gitjournal/screens/settings_git_remote.dart';
56

67
import 'package:dynamic_theme/dynamic_theme.dart';
78

@@ -143,6 +144,16 @@ class SettingsListState extends State<SettingsList> {
143144
SettingsHeader("Git Author Settings"),
144145
ListTile(title: gitAuthorForm),
145146
ListTile(title: gitAuthorEmailForm),
147+
ListTile(
148+
title: const Text("Git Remote Settings"),
149+
subtitle: const Text("Configure where your notes are synced"),
150+
onTap: () {
151+
var route = MaterialPageRoute(
152+
builder: (context) => GitRemoteSettingsScreen(),
153+
);
154+
Navigator.of(context).push(route);
155+
},
156+
),
146157
const SizedBox(height: 16.0),
147158
SettingsHeader("Storage"),
148159
ListPreference(

0 commit comments

Comments
 (0)