mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
KeyEditor: Do not let Next work until valid values are provided
This commit is contained in:
@ -1,13 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class PublicKeyEditor extends StatelessWidget {
|
class PublicKeyEditor extends StatelessWidget {
|
||||||
final TextEditingController controller;
|
final Function valueChanged;
|
||||||
|
|
||||||
PublicKeyEditor(this.controller);
|
PublicKeyEditor(this.valueChanged);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return KeyEditor(controller, _validator);
|
return KeyEditor(valueChanged, _validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _validator(String val) {
|
String _validator(String val) {
|
||||||
@ -19,13 +19,13 @@ class PublicKeyEditor extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PrivateKeyEditor extends StatelessWidget {
|
class PrivateKeyEditor extends StatelessWidget {
|
||||||
final TextEditingController controller;
|
final Function valueChanged;
|
||||||
|
|
||||||
PrivateKeyEditor(this.controller);
|
PrivateKeyEditor(this.valueChanged);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return KeyEditor(controller, _validator);
|
return KeyEditor(valueChanged, _validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _validator(String val) {
|
String _validator(String val) {
|
||||||
@ -40,13 +40,33 @@ class PrivateKeyEditor extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class KeyEditor extends StatelessWidget {
|
class KeyEditor extends StatelessWidget {
|
||||||
final TextEditingController controller;
|
final Function valueChanged;
|
||||||
final Function validator;
|
final Function validator;
|
||||||
|
|
||||||
KeyEditor(this.controller, this.validator);
|
KeyEditor(this.valueChanged, this.validator);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var form = Form(
|
||||||
|
child: Builder(builder: (context) {
|
||||||
|
return TextFormField(
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
maxLines: null,
|
||||||
|
style: Theme.of(context).textTheme.body1,
|
||||||
|
autovalidate: true,
|
||||||
|
validator: validator,
|
||||||
|
onChanged: (String newVal) {
|
||||||
|
if (Form.of(context).validate()) {
|
||||||
|
valueChanged(newVal);
|
||||||
|
} else {
|
||||||
|
valueChanged("");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
autovalidate: true,
|
||||||
|
);
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 80.0,
|
height: 80.0,
|
||||||
@ -55,14 +75,7 @@ class KeyEditor extends StatelessWidget {
|
|||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: TextFormField(
|
child: form,
|
||||||
controller: controller,
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
maxLines: null,
|
|
||||||
style: Theme.of(context).textTheme.body1,
|
|
||||||
autovalidate: true,
|
|
||||||
validator: validator,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -207,11 +207,14 @@ class GitHostUserProvidedKeys extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
||||||
|
String publicKey = "";
|
||||||
|
String privateKey = "";
|
||||||
final _publicKeyController = TextEditingController();
|
final _publicKeyController = TextEditingController();
|
||||||
final _privateKeyController = TextEditingController();
|
final _privateKeyController = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var nextEnabled = publicKey.isNotEmpty && privateKey.isNotEmpty;
|
||||||
return Container(
|
return Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -220,18 +223,30 @@ class _GitHostUserProvidedKeysState extends State<GitHostUserProvidedKeys> {
|
|||||||
style: Theme.of(context).textTheme.headline,
|
style: Theme.of(context).textTheme.headline,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
PublicKeyEditor(_publicKeyController),
|
PublicKeyEditor((String newVal) {
|
||||||
|
setState(() {
|
||||||
|
publicKey = newVal;
|
||||||
|
});
|
||||||
|
}),
|
||||||
const SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
Text(
|
Text(
|
||||||
"Private Key -",
|
"Private Key -",
|
||||||
style: Theme.of(context).textTheme.headline,
|
style: Theme.of(context).textTheme.headline,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8.0),
|
const SizedBox(height: 8.0),
|
||||||
PrivateKeyEditor(_privateKeyController),
|
PrivateKeyEditor((String newVal) {
|
||||||
|
setState(() {
|
||||||
|
privateKey = newVal;
|
||||||
|
});
|
||||||
|
}),
|
||||||
const SizedBox(height: 16.0),
|
const SizedBox(height: 16.0),
|
||||||
GitHostSetupButton(
|
GitHostSetupButton(
|
||||||
text: "Next",
|
text: "Next",
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
if (!nextEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var publicKey = _publicKeyController.text.trim();
|
var publicKey = _publicKeyController.text.trim();
|
||||||
var privateKey = _privateKeyController.text.trim();
|
var privateKey = _privateKeyController.text.trim();
|
||||||
widget.doneFunction(publicKey, privateKey);
|
widget.doneFunction(publicKey, privateKey);
|
||||||
|
Reference in New Issue
Block a user