mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Move onboarding git clone
screen to its own file
This commit is contained in:
115
lib/screens/onboarding_git_clone.dart
Normal file
115
lib/screens/onboarding_git_clone.dart
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
|
import 'package:journal/analytics.dart';
|
||||||
|
import 'package:journal/state_container.dart';
|
||||||
|
import 'package:journal/storage/git.dart';
|
||||||
|
|
||||||
|
class OnBoardingGitClone extends StatefulWidget {
|
||||||
|
final Function doneFunction;
|
||||||
|
|
||||||
|
OnBoardingGitClone({@required this.doneFunction});
|
||||||
|
|
||||||
|
@override
|
||||||
|
OnBoardingGitCloneState createState() {
|
||||||
|
return new OnBoardingGitCloneState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
||||||
|
String errorMessage = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
// FIXME: This is throwing an exception!
|
||||||
|
_initStateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _initStateAsync() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
String sshCloneUrl = pref.getString("sshCloneUrl");
|
||||||
|
|
||||||
|
// Just in case it was half cloned because of an error
|
||||||
|
await _removeExistingClone();
|
||||||
|
|
||||||
|
String error = await gitClone(sshCloneUrl, "journal");
|
||||||
|
if (error != null && error.isNotEmpty) {
|
||||||
|
setState(() {
|
||||||
|
getAnalytics().logEvent(
|
||||||
|
name: "onboarding_gitClone_error",
|
||||||
|
parameters: <String, dynamic>{
|
||||||
|
'error': error,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
errorMessage = error;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.widget.doneFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future _removeExistingClone() async {
|
||||||
|
var baseDir = await getNotesDir();
|
||||||
|
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
||||||
|
bool exists = await dotGitDir.exists();
|
||||||
|
if (exists) {
|
||||||
|
await baseDir.delete(recursive: true);
|
||||||
|
await baseDir.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var children = <Widget>[];
|
||||||
|
if (this.errorMessage.isEmpty) {
|
||||||
|
children = <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'Cloning ...',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.display1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8.0),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
} else if (this.errorMessage.isNotEmpty) {
|
||||||
|
children = <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
'Failed',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.display1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
this.errorMessage,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.display1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: children,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@ -12,6 +10,7 @@ import 'package:journal/state_container.dart';
|
|||||||
import 'package:journal/storage/git.dart';
|
import 'package:journal/storage/git.dart';
|
||||||
|
|
||||||
import 'package:journal/screens/onboarding_git_url.dart';
|
import 'package:journal/screens/onboarding_git_url.dart';
|
||||||
|
import 'package:journal/screens/onboarding_git_clone.dart';
|
||||||
|
|
||||||
class OnBoardingScreen extends StatefulWidget {
|
class OnBoardingScreen extends StatefulWidget {
|
||||||
final Function onBoardingCompletedFunction;
|
final Function onBoardingCompletedFunction;
|
||||||
@ -417,106 +416,3 @@ class OnBoardingSshKey extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class OnBoardingGitClone extends StatefulWidget {
|
|
||||||
final Function doneFunction;
|
|
||||||
|
|
||||||
OnBoardingGitClone({@required this.doneFunction});
|
|
||||||
|
|
||||||
@override
|
|
||||||
OnBoardingGitCloneState createState() {
|
|
||||||
return new OnBoardingGitCloneState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class OnBoardingGitCloneState extends State<OnBoardingGitClone> {
|
|
||||||
String errorMessage = "";
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_initStateAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _initStateAsync() async {
|
|
||||||
var pref = await SharedPreferences.getInstance();
|
|
||||||
String sshCloneUrl = pref.getString("sshCloneUrl");
|
|
||||||
|
|
||||||
// Just in case it was half cloned because of an error
|
|
||||||
await _removeExistingClone();
|
|
||||||
|
|
||||||
String error = await gitClone(sshCloneUrl, "journal");
|
|
||||||
if (error != null && error.isNotEmpty) {
|
|
||||||
setState(() {
|
|
||||||
getAnalytics().logEvent(
|
|
||||||
name: "onboarding_gitClone_error",
|
|
||||||
parameters: <String, dynamic>{
|
|
||||||
'error': error,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
errorMessage = error;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.widget.doneFunction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future _removeExistingClone() async {
|
|
||||||
var baseDir = await getNotesDir();
|
|
||||||
var dotGitDir = new Directory(p.join(baseDir.path, ".git"));
|
|
||||||
bool exists = await dotGitDir.exists();
|
|
||||||
if (exists) {
|
|
||||||
await baseDir.delete(recursive: true);
|
|
||||||
await baseDir.create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
var children = <Widget>[];
|
|
||||||
if (this.errorMessage.isEmpty) {
|
|
||||||
children = <Widget>[
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
'Cloning ...',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.display1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(height: 8.0),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
value: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
} else if (this.errorMessage.isNotEmpty) {
|
|
||||||
children = <Widget>[
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
'Failed',
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.display1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
this.errorMessage,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: Theme.of(context).textTheme.display1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: children,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user