Skip to content

Commit

Permalink
fix upper case issue for join group code in particular device
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-ishita-g committed Dec 17, 2024
1 parent c7d173a commit 174fe3f
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions app/lib/ui/flow/space/join/join_space_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:style/button/bottom_sticky_overlay.dart';
Expand Down Expand Up @@ -33,17 +32,20 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {

@override
void initState() {
_controllers = List.generate(6, (index) => TextEditingController());
_focusNodes = List.generate(
6,
(index) => FocusNode(onKeyEvent: (node, event) {
if (event.logicalKey == LogicalKeyboardKey.backspace &&
_controllers[index].text.isEmpty) {
if (index > 0) _focusNodes[index - 1].requestFocus();
}
return KeyEventResult.ignored;
}));
super.initState();
_controllers = List.generate(6, (index) => TextEditingController());
_focusNodes = List.generate(6, (index) => FocusNode());
}

@override
void dispose() {
for (var controller in _controllers) {
controller.dispose();
}
for (var focusNode in _focusNodes) {
focusNode.dispose();
}
super.dispose();
}

@override
Expand Down Expand Up @@ -130,11 +132,11 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
}

Widget _buildCodeBox(
BuildContext context,
double width,
int index,
JoinSpaceViewState state,
) {
BuildContext context,
double width,
int index,
JoinSpaceViewState state,
) {
return Container(
width: width,
height: 64,
Expand All @@ -161,6 +163,14 @@ class _JoinSpaceState extends ConsumerState<JoinSpace> {
FocusManager.instance.primaryFocus?.unfocus();
},
onChanged: (text) {
final upperCaseText = text.toUpperCase();
if (_controllers[index].text != upperCaseText) {
_controllers[index].value = TextEditingValue(
text: upperCaseText,
selection: TextSelection.collapsed(offset: upperCaseText.length),
);
}

if (text.isEmpty) {
if (index > 0) _focusNodes[index - 1].requestFocus();
} else {
Expand Down

0 comments on commit 174fe3f

Please sign in to comment.