From 11796de5d7566bcffa732e18c400704421e21724 Mon Sep 17 00:00:00 2001 From: open-trade Date: Thu, 26 Nov 2020 00:47:52 +0800 Subject: [PATCH] try form --- flutter_hbb/lib/home_page.dart | 53 +++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/flutter_hbb/lib/home_page.dart b/flutter_hbb/lib/home_page.dart index cef284e8e..8dcb57cc2 100644 --- a/flutter_hbb/lib/home_page.dart +++ b/flutter_hbb/lib/home_page.dart @@ -210,22 +210,46 @@ class _HomePageState extends State { } void showServer(BuildContext context) { + final formKey = GlobalKey(); + var id = ''; + var relay = ''; showAlertDialog( context, (setState) => Tuple3( Text('ID/Relay Server'), - Column(mainAxisSize: MainAxisSize.min, children: [ - TextFormField( - decoration: InputDecoration( - labelText: 'ID Server', - ), - ), - TextFormField( - decoration: InputDecoration( - labelText: 'Relay Server', - ), - ), - ]), + Form( + key: formKey, + child: + Column(mainAxisSize: MainAxisSize.min, children: [ + TextFormField( + decoration: InputDecoration( + labelText: 'ID Server', + ), + validator: (value) { + if (value.isEmpty) { + return 'Please enter valid server address'; + } + return null; + }, + onSaved: (String value) { + id = value; + }, + ), + TextFormField( + decoration: InputDecoration( + labelText: 'Relay Server', + ), + validator: (value) { + if (value.isEmpty) { + return 'Please enter valid server address'; + } + return null; + }, + onSaved: (String value) { + relay = value; + }, + ), + ])), [ FlatButton( textColor: MyTheme.accent, @@ -237,7 +261,10 @@ void showServer(BuildContext context) { FlatButton( textColor: MyTheme.accent, onPressed: () { - Navigator.pop(context); + if (formKey.currentState.validate()) { + formKey.currentState.save(); + Navigator.pop(context); + } }, child: Text('OK'), ),