Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[auth] Limit text field length

Neeraj Gupta583163968d4f
diff --git a/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
index cfede00824..df3c102750 100644
--- a/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
+++ b/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
@@ -29,6 +29,8 @@ class SetupEnterSecretKeyPage extends StatefulWidget {
}
class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
+ final int _notesLimit = 500;
+ final int _otherTextLimit = 200;
late TextEditingController _issuerController;
late TextEditingController _accountController;
late TextEditingController _secretController;
@@ -54,9 +56,29 @@ class _SetupEnterSecretKeyPageState extends State<SetupEnterSecretKeyPage> {
_streamSubscription = Bus.instance.on<CodesUpdatedEvent>().listen((event) {
_loadTags();
});
+
+ if (widget.code == null ||
+ (widget.code!.issuer.length < _otherTextLimit &&
+ widget.code!.account.length < _otherTextLimit &&
+ widget.code!.secret.length < _otherTextLimit)) {
+ _limitTextLength(_issuerController, _otherTextLimit);
+ _limitTextLength(_accountController, _otherTextLimit);
+ _limitTextLength(_secretController, _otherTextLimit);
+ }
super.initState();
}
+ void _limitTextLength(TextEditingController controller, int limit) {
+ controller.addListener(() {
+ if (controller.text.length > limit) {
+ controller.text = controller.text.substring(0, limit);
+ controller.selection = TextSelection.fromPosition(
+ TextPosition(offset: controller.text.length),
+ );
+ }
+ });
+ }
+
@override
void dispose() {
_streamSubscription?.cancel();