diff --git a/lib/screens/onboarding_screens.dart b/lib/screens/onboarding_screens.dart index df87641a..7682d42b 100644 --- a/lib/screens/onboarding_screens.dart +++ b/lib/screens/onboarding_screens.dart @@ -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 { } 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 { + 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 { 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 { } } -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 { + 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 = []; + if (this.errorMessage.isEmpty) { + children = [ + Text( + 'Cloning ...', + textAlign: TextAlign.center, + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38), + ), + CircularProgressIndicator( + value: null, + ), + ]; + } else { + children = [ + 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, + ), + ), + ); } } diff --git a/lib/storage/git.dart b/lib/storage/git.dart index a532d282..62057706 100644 --- a/lib/storage/git.dart +++ b/lib/storage/git.dart @@ -13,7 +13,7 @@ Future getGitBaseDirectory() async { return new Directory(path); } -Future gitClone(String cloneUrl, String folderName) async { +Future 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 generateSSHKeys() async {