fix: infinite loading (#5613)

This commit is contained in:
Lucas.Xu 2024-06-24 20:14:22 +08:00 committed by GitHub
parent d2ca41c8f5
commit 40312f4260
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 33 deletions

View File

@ -1,6 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart'; import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart'; import 'package:appflowy/plugins/document/presentation/editor_page.dart';
@ -13,6 +10,8 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart'; import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection; import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra/theme_extension.dart'; import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
Map<String, BlockComponentBuilder> getEditorBuilderMap({ Map<String, BlockComponentBuilder> getEditorBuilderMap({

View File

@ -1,8 +1,5 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart'; import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_configuration.dart'; import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
@ -31,6 +28,8 @@ import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart'; import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
final codeBlockLocalization = CodeBlockLocalizations( final codeBlockLocalization = CodeBlockLocalizations(

View File

@ -188,7 +188,7 @@ class _AutoCompletionBlockComponentState
Future<void> _onGenerate() async { Future<void> _onGenerate() async {
final loading = Loading(context); final loading = Loading(context);
await loading.start(); loading.start();
await _updateEditingText(); await _updateEditingText();
@ -218,7 +218,7 @@ class _AutoCompletionBlockComponentState
await loading.stop(); await loading.stop();
if (mounted) { if (mounted) {
barrierDialog = BarrierDialog(context); barrierDialog = BarrierDialog(context);
await barrierDialog?.show(); barrierDialog?.show();
await _makeSurePreviousNodeIsEmptyParagraphNode(); await _makeSurePreviousNodeIsEmptyParagraphNode();
} }
}, },
@ -273,7 +273,7 @@ class _AutoCompletionBlockComponentState
} }
final loading = Loading(context); final loading = Loading(context);
await loading.start(); loading.start();
// clear previous response // clear previous response
final selection = startSelection; final selection = startSelection;
if (selection != null) { if (selection != null) {

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Loading { class Loading {
@ -6,22 +8,24 @@ class Loading {
BuildContext? loadingContext; BuildContext? loadingContext;
final BuildContext context; final BuildContext context;
Future<void> start() async => showDialog<void>( void start() => unawaited(
context: context, showDialog<void>(
barrierDismissible: false, context: context,
builder: (BuildContext context) { barrierDismissible: false,
loadingContext = context; builder: (BuildContext context) {
return const SimpleDialog( loadingContext = context;
elevation: 0.0, return const SimpleDialog(
backgroundColor: elevation: 0.0,
Colors.transparent, // can change this to your preferred color backgroundColor:
children: [ Colors.transparent, // can change this to your preferred color
Center( children: [
child: CircularProgressIndicator(), Center(
), child: CircularProgressIndicator(),
], ),
); ],
}, );
},
),
); );
Future<void> stop() async { Future<void> stop() async {
@ -38,14 +42,16 @@ class BarrierDialog {
late BuildContext loadingContext; late BuildContext loadingContext;
final BuildContext context; final BuildContext context;
Future<void> show() async => showDialog<void>( void show() => unawaited(
context: context, showDialog<void>(
barrierDismissible: false, context: context,
barrierColor: Colors.transparent, barrierDismissible: false,
builder: (BuildContext context) { barrierColor: Colors.transparent,
loadingContext = context; builder: (BuildContext context) {
return const SizedBox.shrink(); loadingContext = context;
}, return const SizedBox.shrink();
},
),
); );
Future<void> dismiss() async => Navigator.of(loadingContext).pop(); Future<void> dismiss() async => Navigator.of(loadingContext).pop();