mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
KeyEditors: Remove code duplication
This commit is contained in:
@ -7,31 +7,14 @@ class PublicKeyEditor extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return KeyEditor(controller, _validator);
|
||||||
width: double.infinity,
|
}
|
||||||
height: 80.0,
|
|
||||||
child: Container(
|
String _validator(String val) {
|
||||||
color: Theme.of(context).buttonColor,
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: TextFormField(
|
|
||||||
controller: controller,
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
maxLines: null,
|
|
||||||
style: Theme.of(context).textTheme.body1,
|
|
||||||
autovalidate: true,
|
|
||||||
validator: (String val) {
|
|
||||||
if (!val.startsWith("ssh-")) {
|
if (!val.startsWith("ssh-")) {
|
||||||
return "Invalid Public Key";
|
return "Invalid Public Key";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +23,28 @@ class PrivateKeyEditor extends StatelessWidget {
|
|||||||
|
|
||||||
PrivateKeyEditor(this.controller);
|
PrivateKeyEditor(this.controller);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return KeyEditor(controller, _validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _validator(String val) {
|
||||||
|
if (!val.startsWith("-----BEGIN RSA PRIVATE KEY-----")) {
|
||||||
|
return "Invalid Private Key";
|
||||||
|
}
|
||||||
|
if (!val.startsWith("-----END RSA PRIVATE KEY-----")) {
|
||||||
|
return "Invalid Private Key";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeyEditor extends StatelessWidget {
|
||||||
|
final TextEditingController controller;
|
||||||
|
final Function validator;
|
||||||
|
|
||||||
|
KeyEditor(this.controller, this.validator);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
@ -56,15 +61,7 @@ class PrivateKeyEditor extends StatelessWidget {
|
|||||||
maxLines: null,
|
maxLines: null,
|
||||||
style: Theme.of(context).textTheme.body1,
|
style: Theme.of(context).textTheme.body1,
|
||||||
autovalidate: true,
|
autovalidate: true,
|
||||||
validator: (String val) {
|
validator: validator,
|
||||||
if (!val.startsWith("-----BEGIN RSA PRIVATE KEY-----")) {
|
|
||||||
return "Invalid Private Key";
|
|
||||||
}
|
|
||||||
if (!val.startsWith("-----END RSA PRIVATE KEY-----")) {
|
|
||||||
return "Invalid Private Key";
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user