mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-06-29 02:03:10 -04:00
49 lines
1.1 KiB
Dart
49 lines
1.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class Loading {
|
|
Loading(this.context);
|
|
|
|
BuildContext? loadingContext;
|
|
final BuildContext context;
|
|
|
|
bool hasStopped = false;
|
|
|
|
void start() => unawaited(
|
|
showDialog<void>(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
loadingContext = context;
|
|
|
|
if (hasStopped) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
Navigator.of(loadingContext!).maybePop();
|
|
loadingContext = null;
|
|
});
|
|
}
|
|
|
|
return const SimpleDialog(
|
|
elevation: 0.0,
|
|
backgroundColor:
|
|
Colors.transparent, // can change this to your preferred color
|
|
children: [
|
|
Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
|
|
void stop() {
|
|
if (loadingContext != null) {
|
|
Navigator.of(loadingContext!).pop();
|
|
loadingContext = null;
|
|
}
|
|
|
|
hasStopped = true;
|
|
}
|
|
}
|