Skip to content

Commit

Permalink
fix: infinite loading (#5613)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jun 24, 2024
1 parent d2ca41c commit 40312f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
Expand All @@ -13,6 +10,8 @@ import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Map<String, BlockComponentBuilder> getEditorBuilderMap({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
Expand Down Expand Up @@ -31,6 +28,8 @@ import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.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';

final codeBlockLocalization = CodeBlockLocalizations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class _AutoCompletionBlockComponentState

Future<void> _onGenerate() async {
final loading = Loading(context);
await loading.start();
loading.start();

await _updateEditingText();

Expand Down Expand Up @@ -218,7 +218,7 @@ class _AutoCompletionBlockComponentState
await loading.stop();
if (mounted) {
barrierDialog = BarrierDialog(context);
await barrierDialog?.show();
barrierDialog?.show();
await _makeSurePreviousNodeIsEmptyParagraphNode();
}
},
Expand Down Expand Up @@ -273,7 +273,7 @@ class _AutoCompletionBlockComponentState
}

final loading = Loading(context);
await loading.start();
loading.start();
// clear previous response
final selection = startSelection;
if (selection != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';

class Loading {
Expand All @@ -6,22 +8,24 @@ class Loading {
BuildContext? loadingContext;
final BuildContext context;

Future<void> start() async => showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
loadingContext = context;
return const SimpleDialog(
elevation: 0.0,
backgroundColor:
Colors.transparent, // can change this to your preferred color
children: [
Center(
child: CircularProgressIndicator(),
),
],
);
},
void start() => unawaited(
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
loadingContext = context;
return const SimpleDialog(
elevation: 0.0,
backgroundColor:
Colors.transparent, // can change this to your preferred color
children: [
Center(
child: CircularProgressIndicator(),
),
],
);
},
),
);

Future<void> stop() async {
Expand All @@ -38,14 +42,16 @@ class BarrierDialog {
late BuildContext loadingContext;
final BuildContext context;

Future<void> show() async => showDialog<void>(
context: context,
barrierDismissible: false,
barrierColor: Colors.transparent,
builder: (BuildContext context) {
loadingContext = context;
return const SizedBox.shrink();
},
void show() => unawaited(
showDialog<void>(
context: context,
barrierDismissible: false,
barrierColor: Colors.transparent,
builder: (BuildContext context) {
loadingContext = context;
return const SizedBox.shrink();
},
),
);

Future<void> dismiss() async => Navigator.of(loadingContext).pop();
Expand Down

0 comments on commit 40312f4

Please sign in to comment.