mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-14 15:33:04 +08:00
Add a gitClone page on the onBoarding screens
This commit is contained in:
@ -20,7 +20,13 @@ class OnBoardingScreen extends StatelessWidget {
|
|||||||
pref.setString("sshCloneUrl", sshUrl);
|
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 {
|
class OnBoardingSshKey extends StatefulWidget {
|
||||||
|
final Function doneFunction;
|
||||||
|
|
||||||
|
OnBoardingSshKey({@required this.doneFunction});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
OnBoardingSshKeyState createState() {
|
OnBoardingSshKeyState createState() {
|
||||||
return new OnBoardingSshKeyState();
|
return new OnBoardingSshKeyState(doneFunction: this.doneFunction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
|
class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
|
||||||
|
final Function doneFunction;
|
||||||
|
|
||||||
String publicKey = "Generating ...";
|
String publicKey = "Generating ...";
|
||||||
|
|
||||||
|
OnBoardingSshKeyState({@required this.doneFunction});
|
||||||
|
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
generateSSHKeys().then((String _publicKey) {
|
generateSSHKeys().then((String _publicKey) {
|
||||||
@ -126,10 +140,8 @@ class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
|
|||||||
style: TextStyle(fontSize: 10),
|
style: TextStyle(fontSize: 10),
|
||||||
),
|
),
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
child: Text("Click when Loaded"),
|
child: Text("Start Clone"),
|
||||||
onPressed: () {
|
onPressed: this.doneFunction,
|
||||||
print("Button pressed");
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -138,9 +150,73 @@ class OnBoardingSshKeyState extends State<OnBoardingSshKey> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingGitClone extends StatelessWidget {
|
class OnBoardingGitClone extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
OnBoardingGitCloneState createState() {
|
||||||
return Text("Cloning");
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ Future<Directory> getGitBaseDirectory() async {
|
|||||||
return new Directory(path);
|
return new Directory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future gitClone(String cloneUrl, String folderName) async {
|
Future<String> gitClone(String cloneUrl, String folderName) async {
|
||||||
print("Going to git clone");
|
print("Going to git clone");
|
||||||
try {
|
try {
|
||||||
await _platform.invokeMethod('gitClone', {
|
await _platform.invokeMethod('gitClone', {
|
||||||
@ -23,7 +23,10 @@ Future gitClone(String cloneUrl, String folderName) async {
|
|||||||
print("Done");
|
print("Done");
|
||||||
} on PlatformException catch (e) {
|
} on PlatformException catch (e) {
|
||||||
print("gitClone Failed: '${e.message}'.");
|
print("gitClone Failed: '${e.message}'.");
|
||||||
|
return e.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> generateSSHKeys() async {
|
Future<String> generateSSHKeys() async {
|
||||||
|
Reference in New Issue
Block a user