mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 17:29:50 +08:00
OnBoarding Git Url: Move to its own file
This onboarding file is getting too huge
This commit is contained in:
92
lib/screens/onboarding_git_url.dart
Normal file
92
lib/screens/onboarding_git_url.dart
Normal file
@ -0,0 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class OnBoardingGitUrl extends StatefulWidget {
|
||||
final Function doneFunction;
|
||||
|
||||
OnBoardingGitUrl({@required this.doneFunction});
|
||||
|
||||
@override
|
||||
OnBoardingGitUrlState createState() {
|
||||
return new OnBoardingGitUrlState();
|
||||
}
|
||||
}
|
||||
|
||||
class OnBoardingGitUrlState extends State<OnBoardingGitUrl> {
|
||||
final GlobalKey<FormFieldState<String>> sshUrlKey =
|
||||
GlobalKey<FormFieldState<String>>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final inputFormFocus = FocusNode();
|
||||
|
||||
final formSubmitted = () {
|
||||
if (_formKey.currentState.validate()) {
|
||||
_formKey.currentState.save();
|
||||
|
||||
var url = sshUrlKey.currentState.value;
|
||||
this.widget.doneFunction(url);
|
||||
inputFormFocus.unfocus();
|
||||
}
|
||||
};
|
||||
|
||||
var inputForm = Form(
|
||||
key: _formKey,
|
||||
child: TextFormField(
|
||||
key: sshUrlKey,
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
style: Theme.of(context).textTheme.title,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Eg: git@github.com:GitJournal/GitJournal.git',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter some text';
|
||||
}
|
||||
if (value.startsWith('https://') || value.startsWith('http://')) {
|
||||
return 'Only SSH urls are currently accepted';
|
||||
}
|
||||
|
||||
RegExp regExp = new RegExp(r"[a-zA-Z0-9.]+@[a-zA-Z0-9.]+:.+");
|
||||
if (!regExp.hasMatch(value)) {
|
||||
return "Invalid Input";
|
||||
}
|
||||
},
|
||||
focusNode: inputFormFocus,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (String _) => formSubmitted(),
|
||||
),
|
||||
);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Enter the Git SSH URL',
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.display1,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: new Container(
|
||||
color: Theme.of(context).primaryColorLight,
|
||||
child: inputForm,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: RaisedButton(
|
||||
child: Text("Next"),
|
||||
onPressed: formSubmitted,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ import 'package:journal/analytics.dart';
|
||||
import 'package:journal/state_container.dart';
|
||||
import 'package:journal/storage/git.dart';
|
||||
|
||||
import 'package:journal/screens/onboarding_git_url.dart';
|
||||
|
||||
class OnBoardingScreen extends StatefulWidget {
|
||||
final Function onBoardingCompletedFunction;
|
||||
|
||||
@ -395,96 +397,6 @@ class OnBoardingCreateRepo extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class OnBoardingGitUrl extends StatefulWidget {
|
||||
final Function doneFunction;
|
||||
|
||||
OnBoardingGitUrl({@required this.doneFunction});
|
||||
|
||||
@override
|
||||
OnBoardingGitUrlState createState() {
|
||||
return new OnBoardingGitUrlState();
|
||||
}
|
||||
}
|
||||
|
||||
class OnBoardingGitUrlState extends State<OnBoardingGitUrl> {
|
||||
final GlobalKey<FormFieldState<String>> sshUrlKey =
|
||||
GlobalKey<FormFieldState<String>>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final inputFormFocus = FocusNode();
|
||||
|
||||
final formSubmitted = () {
|
||||
if (_formKey.currentState.validate()) {
|
||||
_formKey.currentState.save();
|
||||
|
||||
var url = sshUrlKey.currentState.value;
|
||||
this.widget.doneFunction(url);
|
||||
inputFormFocus.unfocus();
|
||||
}
|
||||
};
|
||||
|
||||
var inputForm = Form(
|
||||
key: _formKey,
|
||||
child: TextFormField(
|
||||
key: sshUrlKey,
|
||||
textAlign: TextAlign.center,
|
||||
autofocus: true,
|
||||
style: Theme.of(context).textTheme.title,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Eg: git@github.com:GitJournal/GitJournal.git',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return 'Please enter some text';
|
||||
}
|
||||
if (value.startsWith('https://') || value.startsWith('http://')) {
|
||||
return 'Only SSH urls are currently accepted';
|
||||
}
|
||||
|
||||
RegExp regExp = new RegExp(r"[a-zA-Z0-9.]+@[a-zA-Z0-9.]+:.+");
|
||||
if (!regExp.hasMatch(value)) {
|
||||
return "Invalid Input";
|
||||
}
|
||||
},
|
||||
focusNode: inputFormFocus,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (String _) => formSubmitted(),
|
||||
),
|
||||
);
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
'Enter the Git SSH URL',
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.display1,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: new Container(
|
||||
color: Theme.of(context).primaryColorLight,
|
||||
child: inputForm,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: RaisedButton(
|
||||
child: Text("Next"),
|
||||
onPressed: formSubmitted,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class OnBoardingSshKey extends StatelessWidget {
|
||||
final Function doneFunction;
|
||||
final String publicKey;
|
||||
|
Reference in New Issue
Block a user