Skip to content

Commit

Permalink
add switch to disable URL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vauvenal5 committed Jan 7, 2021
1 parent f007503 commit 2ec18b5
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 36 deletions.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/1600.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- add switch to disable URL validation in login mask
73 changes: 39 additions & 34 deletions lib/views/screens/nc_address_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:yaga/views/screens/nc_login_screen.dart';
import 'package:yaga/views/screens/yaga_home_screen.dart';
import 'package:string_validator/string_validator.dart';
import 'package:yaga/views/widgets/address_form_advanced.dart';
import 'package:yaga/views/widgets/address_form_simple.dart';

class NextCloudAddressScreen extends StatefulWidget {
static const route = "/nc/address";
Expand All @@ -13,46 +14,32 @@ class NextCloudAddressScreen extends StatefulWidget {
}

class _NextCloudAddressScreenState extends State<NextCloudAddressScreen> {
final _formKey = GlobalKey<FormState>();

String _addHttps(String value) {
if (value.startsWith("https://")) {
return value;
}

return "https://" + value;
}
GlobalKey<FormState> _formKey = GlobalKey<FormState>();
bool validation = true;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Server Address"),
actions: [
IconButton(
icon: validation ? Icon(Icons.report) : Icon(Icons.report_off),
onPressed: () => setState(() {
validation = !validation;
_formKey = GlobalKey<FormState>();
}),
),
],
),
body: Center(
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: TextFormField(
decoration: InputDecoration(
labelText: "Nextcloud Server address https://...",
icon: Icon(Icons.cloud_queue)),
onSaved: (value) => Navigator.pushNamed(
context, NextCloudLoginScreen.route,
arguments: Uri.parse('https://${rtrim(value, "/")}')),
validator: (value) {
if (value.startsWith("https://") ||
value.startsWith("http://")) {
return "Https will be added automaically.";
}
return isURL("https://$value")
? null
: "Please enter a valid URL.";
},
),
))),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: validation
? AddressFormSimple(_formKey, _onSave)
: AddressFormAdvanced(_formKey, _onSave),
),
),
resizeToAvoidBottomInset: true,
bottomNavigationBar: BottomNavigationBar(
currentIndex: 1,
Expand All @@ -66,7 +53,9 @@ class _NextCloudAddressScreenState extends State<NextCloudAddressScreen> {
}

Navigator.popUntil(
context, ModalRoute.withName(YagaHomeScreen.route));
context,
ModalRoute.withName(YagaHomeScreen.route),
);
},
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
Expand All @@ -80,4 +69,20 @@ class _NextCloudAddressScreenState extends State<NextCloudAddressScreen> {
],
));
}

String _addHttps(String value) {
if (value.startsWith("https://")) {
return value;
}

return "https://" + value;
}

void _onSave(Uri uri) {
Navigator.pushNamed(
context,
NextCloudLoginScreen.route,
arguments: uri,
);
}
}
26 changes: 26 additions & 0 deletions lib/views/widgets/address_form_advanced.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:string_validator/string_validator.dart';

class AddressFormAdvanced extends StatelessWidget {
final GlobalKey<FormState> _formKey;
final Function(Uri) _onSave;

AddressFormAdvanced(this._formKey, this._onSave);

@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
decoration: InputDecoration(
labelText: "Fully qualified Nextcloud Server address...",
icon: Icon(Icons.cloud_queue),
helperStyle: TextStyle(color: Colors.orange),
helperText: "Validation is disabled."),
onSaved: (value) => _onSave(Uri.parse(rtrim(value, "/"))),
initialValue: "https://",
),
);
}
}
29 changes: 29 additions & 0 deletions lib/views/widgets/address_form_simple.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'package:string_validator/string_validator.dart';

class AddressFormSimple extends StatelessWidget {
final GlobalKey<FormState> _formKey;
final Function(Uri) _onSave;

AddressFormSimple(this._formKey, this._onSave);

@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: TextFormField(
decoration: InputDecoration(
labelText: "Nextcloud Server address https://...",
icon: Icon(Icons.cloud_queue)),
onSaved: (value) => _onSave(Uri.parse('https://${rtrim(value, "/")}')),
validator: (value) {
if (value.startsWith("https://") || value.startsWith("http://")) {
return "Https will be added automaically.";
}
return isURL("https://$value") ? null : "Please enter a valid URL.";
},
),
);
}
}
4 changes: 3 additions & 1 deletion lib/views/widgets/remote_image_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class RemoteImageWidget extends StatelessWidget {
return _createIconOverlay(
imageWidget, _getLocalIcon(file, localExists, context));
} else {
getIt.get<NextcloudManagerBridge>().downloadPreviewCommand(_file);
if (getIt.get<NextCloudService>().isUriOfService(_file.uri)) {
getIt.get<NextcloudManagerBridge>().downloadPreviewCommand(_file);
}
}

if (file.localFile != null && localExists) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A Nextcloud gallary app.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.15.11+1511
version: 0.16.0+1600

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit 2ec18b5

Please sign in to comment.