Add a gitClone page on the onBoarding screens

This commit is contained in:
Vishesh Handa
2019-01-10 12:40:45 +01:00
parent 38f7840113
commit a4243768b1
2 changed files with 89 additions and 10 deletions

View File

@ -20,7 +20,13 @@ class OnBoardingScreen extends StatelessWidget {
pref.setString("sshCloneUrl", sshUrl);
});
}),
OnBoardingSshKey(),
OnBoardingSshKey(doneFunction: () {
pageController.nextPage(
duration: Duration(milliseconds: 200),
curve: Curves.easeIn,
);
}),
OnBoardingGitClone(),
],
);
}
@ -84,15 +90,23 @@ class OnBoardingGitUrlState extends State<OnBoardingGitUrl> {
}
class OnBoardingSshKey extends StatefulWidget {
final Function doneFunction;
OnBoardingSshKey({@required this.doneFunction});
@override
OnBoardingSshKeyState createState() {
return new OnBoardingSshKeyState();
return new OnBoardingSshKeyState(doneFunction: this.doneFunction);
}
}
class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
final Function doneFunction;
String publicKey = "Generating ...";
OnBoardingSshKeyState({@required this.doneFunction});
void initState() {
super.initState();
generateSSHKeys().then((String _publicKey) {
@ -126,10 +140,8 @@ class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
style: TextStyle(fontSize: 10),
),
RaisedButton(
child: Text("Click when Loaded"),
onPressed: () {
print("Button pressed");
},
child: Text("Start Clone"),
onPressed: this.doneFunction,
)
],
),
@ -138,9 +150,73 @@ class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
}
}
class OnBoardingGitClone extends StatelessWidget {
class OnBoardingGitClone extends StatefulWidget {
@override
Widget build(BuildContext context) {
return Text("Cloning");
OnBoardingGitCloneState createState() {
return new OnBoardingGitCloneState();
}
}
class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
String errorMessage = "";
@override
void initState() {
_initStateAsync();
}
void _initStateAsync() async {
var pref = await SharedPreferences.getInstance();
String sshCloneUrl = pref.getString("sshCloneUrl");
String error = await gitClone(sshCloneUrl, "journal");
if (error != null && error.isNotEmpty) {
setState(() {
errorMessage = error;
});
}
}
@override
Widget build(BuildContext context) {
var children = <Widget>[];
if (this.errorMessage.isEmpty) {
children = <Widget>[
Text(
'Cloning ...',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38),
),
CircularProgressIndicator(
value: null,
),
];
} else {
children = <Widget>[
Text(
'Failed',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38),
),
Text(
this.errorMessage,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18),
),
];
}
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: children,
),
),
);
}
}

View File

@ -13,7 +13,7 @@ Future<Directory> getGitBaseDirectory() async {
return new Directory(path);
}
Future gitClone(String cloneUrl, String folderName) async {
Future<String> gitClone(String cloneUrl, String folderName) async {
print("Going to git clone");
try {
await _platform.invokeMethod('gitClone', {
@ -23,7 +23,10 @@ Future gitClone(String cloneUrl, String folderName) async {
print("Done");
} on PlatformException catch (e) {
print("gitClone Failed: '${e.message}'.");
return e.message;
}
return null;
}
Future<String> generateSSHKeys() async {