1
0
mirror of https://github.com/GitJournal/GitJournal.git synced 2025-08-06 15:21:21 +08:00

Add some basic onboarding screens

They don't really work out since I don't quite understand how PageView
and the PageController are supposed to work.
This commit is contained in:
Vishesh Handa
2019-01-10 11:54:39 +01:00
parent 4bb02b12d6
commit 38f7840113
6 changed files with 189 additions and 4 deletions
android/app/src/main/java/io/gitjournal/gitjournal
lib
pubspec.lockpubspec.yaml

@ -1,10 +1,14 @@
package io.gitjournal.gitjournal;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import android.os.Bundle;
import android.util.Log;
import org.apache.commons.io.FileUtils;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
@ -125,6 +129,19 @@ public class MainActivity extends FlutterActivity {
new GenerateSSHKeysTask(result).execute(sshKeysLocation, comment);
return;
} else if (call.method.equals("getSSHPublicKey")) {
final String publicKeyPath = sshKeysLocation + "/id_rsa.pub";
String publicKey = "";
try {
publicKey = FileUtils.readFileToString(new File(publicKeyPath), Charset.defaultCharset());
} catch (IOException ex) {
Log.d("GenerateSSHKeys", ex.toString());
result.error("FAILED", "Failed to read the public key", null);
}
result.success(publicKey);
return;
}
result.notImplemented();

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:journal/screens/home_screen.dart';
import 'package:journal/screens/onboarding_screens.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_analytics/observer.dart';
@ -11,9 +12,12 @@ class JournalApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var onBoardingDone = false;
var home = onBoardingDone ? new HomeScreen() : new OnBoardingScreen();
return new MaterialApp(
title: 'Journal',
home: new HomeScreen(),
home: home,
theme: new ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.lightBlue[800],

@ -0,0 +1,146 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:journal/storage/git.dart';
class OnBoardingScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
var pageController = PageController();
return PageView(
controller: pageController,
children: <Widget>[
OnBoardingGitUrl(doneFunction: (String sshUrl) {
pageController.nextPage(
duration: Duration(milliseconds: 200),
curve: Curves.easeIn,
);
SharedPreferences.getInstance().then((SharedPreferences pref) {
pref.setString("sshCloneUrl", sshUrl);
});
}),
OnBoardingSshKey(),
],
);
}
}
class OnBoardingGitUrl extends StatefulWidget {
final Function doneFunction;
OnBoardingGitUrl({@required this.doneFunction});
@override
OnBoardingGitUrlState createState() {
return new OnBoardingGitUrlState(doneFunction: this.doneFunction);
}
}
class OnBoardingGitUrlState extends State<OnBoardingGitUrl> {
final Function doneFunction;
final GlobalKey<FormFieldState<String>> sshUrlKey =
GlobalKey<FormFieldState<String>>();
OnBoardingGitUrlState({@required this.doneFunction});
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
width: double.infinity,
height: double.infinity,
color: Colors.green[400],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Enter the Git SSH URL -',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38),
),
Form(
child: TextFormField(
key: sshUrlKey,
textAlign: TextAlign.center,
autofocus: true,
),
),
RaisedButton(
child: Text("Next"),
onPressed: () {
var url = sshUrlKey.currentState.value;
this.doneFunction(url);
},
)
],
),
),
);
}
}
class OnBoardingSshKey extends StatefulWidget {
@override
OnBoardingSshKeyState createState() {
return new OnBoardingSshKeyState();
}
}
class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
String publicKey = "Generating ...";
void initState() {
super.initState();
generateSSHKeys().then((String _publicKey) {
setState(() {
print("Changing the state");
publicKey = _publicKey;
});
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(
width: double.infinity,
height: double.infinity,
color: Colors.green[400],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Deploy Public Key',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38),
),
Text(
publicKey,
textAlign: TextAlign.center,
maxLines: 10,
style: TextStyle(fontSize: 10),
),
RaisedButton(
child: Text("Click when Loaded"),
onPressed: () {
print("Button pressed");
},
)
],
),
),
);
}
}
class OnBoardingGitClone extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text("Cloning");
}
}

@ -26,14 +26,25 @@ Future gitClone(String cloneUrl, String folderName) async {
}
}
Future generateSSHKeys() async {
Future<String> generateSSHKeys() async {
print("generateSSHKeyss");
try {
String publicKey = await _platform.invokeMethod('generateSSHKeys', {});
print("Public Key " + publicKey);
return publicKey;
} on PlatformException catch (e) {
print("Failed to generateSSHKeys: '${e.message}'.");
}
try {
String publicKey = await _platform.invokeMethod('getSSHPublicKey', {});
print("Public Key " + publicKey);
return publicKey;
} on PlatformException catch (e) {
print("Failed to getSSHPublicKey: '${e.message}'.");
}
return "";
}
Future gitPull(String folderName) async {

@ -103,7 +103,7 @@ packages:
source: hosted
version: "0.13.3+3"
http:
dependency: "direct main"
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
@ -249,6 +249,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
shelf:
dependency: transitive
description:

@ -4,12 +4,12 @@ description: A Journaling App Built on top of Git
dependencies:
flutter:
sdk: flutter
http: "^0.11.3+16"
intl: "^0.15.6"
path: "^1.5.1"
uuid: "^1.0.0"
yaml: "^2.1.13"
firebase_analytics: ^1.1.0
shared_preferences: ^0.4.3
dev_dependencies:
test: ^1.5.1