fix: Create chat dialog crashes sometimes and power level textfield does not validate input

This commit is contained in:
krille-chan 2023-10-28 10:09:40 +02:00
parent c29f9bd44a
commit 5665cac15c
No known key found for this signature in database
3 changed files with 16 additions and 5 deletions

View file

@ -2533,5 +2533,6 @@
"placeholders": { "placeholders": {
"seconds": {} "seconds": {}
} }
} },
"pleaseEnterANumber": "Please enter a number greater than 0"
} }

View file

@ -34,7 +34,7 @@ class LoadProfileBottomSheet extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<ProfileInformation>( return FutureBuilder<ProfileInformation>(
future: Matrix.of(context) future: Matrix.of(outerContext)
.client .client
.getUserProfile(userId) .getUserProfile(userId)
.timeout(const Duration(seconds: 3)), .timeout(const Duration(seconds: 3)),
@ -138,7 +138,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
if (reason == null || reason.single.isEmpty) return; if (reason == null || reason.single.isEmpty) return;
final result = await showFutureLoadingDialog( final result = await showFutureLoadingDialog(
context: context, context: context,
future: () => Matrix.of(context).client.reportContent( future: () => Matrix.of(widget.outerContext).client.reportContent(
user.roomId!, user.roomId!,
user.eventId, user.eventId,
reason: reason.single, reason: reason.single,
@ -203,7 +203,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
case UserBottomSheetAction.message: case UserBottomSheetAction.message:
final roomIdResult = await showFutureLoadingDialog( final roomIdResult = await showFutureLoadingDialog(
context: context, context: context,
future: () => Matrix.of(context) future: () => Matrix.of(widget.outerContext)
.client .client
.startDirectChat(user?.id ?? widget.profile!.userId), .startDirectChat(user?.id ?? widget.profile!.userId),
); );
@ -215,7 +215,7 @@ class UserBottomSheetController extends State<UserBottomSheet> {
if (await askConfirmation()) { if (await askConfirmation()) {
await showFutureLoadingDialog( await showFutureLoadingDialog(
context: context, context: context,
future: () => Matrix.of(context) future: () => Matrix.of(widget.outerContext)
.client .client
.ignoreUser(user?.id ?? widget.profile!.userId), .ignoreUser(user?.id ?? widget.profile!.userId),
); );

View file

@ -61,6 +61,16 @@ Future<int?> showPermissionChooser(
initialText: currentLevel.toString(), initialText: currentLevel.toString(),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
autocorrect: false, autocorrect: false,
validator: (text) {
if (text == null) {
return L10n.of(context)!.pleaseEnterANumber;
}
final level = int.tryParse(text);
if (level == null || level < 0) {
return L10n.of(context)!.pleaseEnterANumber;
}
return null;
},
), ),
], ],
); );