|
|
@ -72,6 +72,21 @@ class _LoginWidgetState extends State<LoginWidget> { |
|
|
|
|
|
|
|
final TextEditingController _usernameController = TextEditingController(); |
|
|
|
final TextEditingController _passwordController = TextEditingController(); |
|
|
|
final TextEditingController _urlController = TextEditingController(); |
|
|
|
|
|
|
|
bool _changedUrl = false; |
|
|
|
String _initialServerUrl = ''; |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
MyProfile.getBaseServerUrl().then((String url) { |
|
|
|
_urlController.text = url; |
|
|
|
_initialServerUrl = url; |
|
|
|
}); |
|
|
|
|
|
|
|
super.initState(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
@ -158,14 +173,12 @@ class _LoginWidgetState extends State<LoginWidget> { |
|
|
|
}, |
|
|
|
), |
|
|
|
const SizedBox(height: 15), |
|
|
|
changeUrl(), |
|
|
|
const SizedBox(height: 20), |
|
|
|
ElevatedButton( |
|
|
|
style: buttonStyle, |
|
|
|
onPressed: () { |
|
|
|
if (_formKey.currentState!.validate()) { |
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
const SnackBar(content: Text('Processing Data')), |
|
|
|
); |
|
|
|
|
|
|
|
login() |
|
|
|
.then((val) { |
|
|
|
Navigator. |
|
|
@ -192,7 +205,70 @@ class _LoginWidgetState extends State<LoginWidget> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget changeUrl() { |
|
|
|
if (_changedUrl) { |
|
|
|
return TextFormField( |
|
|
|
controller: _urlController, |
|
|
|
decoration: InputDecoration( |
|
|
|
hintText: 'URL', |
|
|
|
enabledBorder: OutlineInputBorder( |
|
|
|
borderRadius: BorderRadius.circular(5), |
|
|
|
borderSide: const BorderSide( |
|
|
|
color: Colors.transparent, |
|
|
|
) |
|
|
|
), |
|
|
|
focusedBorder: OutlineInputBorder( |
|
|
|
borderRadius: BorderRadius.circular(5), |
|
|
|
borderSide: const BorderSide( |
|
|
|
color: Colors.transparent, |
|
|
|
) |
|
|
|
), |
|
|
|
), |
|
|
|
style: const TextStyle( |
|
|
|
fontSize: 18, |
|
|
|
), |
|
|
|
// The validator receives the text that the user has entered. |
|
|
|
validator: (value) { |
|
|
|
if (value == null || value.isEmpty) { |
|
|
|
return 'Enter a URL'; |
|
|
|
} |
|
|
|
return null; |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
setState(() { |
|
|
|
_changedUrl = true; |
|
|
|
}); |
|
|
|
}, |
|
|
|
child: Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.end, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
'Change URL', |
|
|
|
style: TextStyle( |
|
|
|
color: Theme.of(context).disabledColor, |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(width: 10), |
|
|
|
Icon( |
|
|
|
Icons.edit, |
|
|
|
color: Theme.of(context).disabledColor, |
|
|
|
size: 14, |
|
|
|
), |
|
|
|
const SizedBox(width: 10), |
|
|
|
], |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Future<dynamic> login() async { |
|
|
|
if (_urlController.text != _initialServerUrl) { |
|
|
|
await MyProfile.setServerUrl(_urlController.text); |
|
|
|
} |
|
|
|
|
|
|
|
final resp = await http.post( |
|
|
|
await MyProfile.getServerUrl('api/v1/login'), |
|
|
|
headers: <String, String>{ |
|
|
|