Skip to content

Commit

Permalink
Create steam dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Nov 15, 2023
1 parent 1c5f99c commit b681ece
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,18 @@ class ChatListController extends State<ChatList>
}

void toggleSelectMode() {
selectModeNotifier.value =
isSelectMode ? SelectMode.normal : SelectMode.select;
// selectModeNotifier.value =
// isSelectMode ? SelectMode.normal : SelectMode.select;
TwakeDialog.showStreamDialogFullScreen(
future: () => Future.delayed(
const Duration(seconds: 10),
),
listen: (state) {
Logs().d(
'ChatListController:: LISTEN State: $state',
);
},
);
}

Future<void> actionWithToggleSelectMode(Function action) async {
Expand Down
156 changes: 156 additions & 0 deletions lib/utils/dialog/stream_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import 'dart:async';
import 'package:flutter/material.dart';

enum StreamDialogState {
loginSSOSuccess,
backupSuccess,
recoveringSuccess,
}

class StreamDialogBuilder extends StatefulWidget {
final Future Function() future;
final Function(StreamDialogState) listen;

const StreamDialogBuilder({
super.key,
required this.future,
required this.listen,
});

@override
State<StreamDialogBuilder> createState() => _StreamDialogBuilderState();
}

class _StreamDialogBuilderState extends State<StreamDialogBuilder>
with TickerProviderStateMixin {
final StreamController<StreamDialogState> streamController =
StreamController<StreamDialogState>.broadcast();

late AnimationController loginSSOProgressController;
late AnimationController backupProgressController;
late AnimationController recoveringProgressController;

static const String loginSSOProgress = 'loginSSOProgress';
static const String backupProgress = 'backupProgress';
static const String recoveringProgress = 'recoveringProgress';

bool _isCompletedFunc = false;

@override
void initState() {
_initial();
streamController.stream.listen((event) {
widget.listen(event);
});

WidgetsBinding.instance.addPostFrameCallback((_) async {
_startLoginSSOProgress();
await widget.future().then((value) {
_isCompletedFunc = true;
});
});

super.initState();
}

void _initial() {
loginSSOProgressController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
backupProgressController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
recoveringProgressController = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
);
}

void _startLoginSSOProgress() {
loginSSOProgressController.addListener(() {
setState(() {});
if (loginSSOProgressController.isCompleted) {
streamController.add(StreamDialogState.loginSSOSuccess);
_startBackupProgress();
}
});
loginSSOProgressController.forward(from: 0);
}

void _startBackupProgress() {
backupProgressController.addListener(() {
setState(() {});
if (backupProgressController.isCompleted) {
streamController.add(StreamDialogState.backupSuccess);
_startRecoveringProgress();
}
});
backupProgressController.forward(from: 0);
}

void _startRecoveringProgress() {
recoveringProgressController.addListener(() {
setState(() {});
if (_isCompletedFunc) {
streamController.add(StreamDialogState.recoveringSuccess);
recoveringProgressController.stop();
Navigator.of(context).pop();
}
});

recoveringProgressController.repeat();
}

@override
void dispose() {
loginSSOProgressController.dispose();
backupProgressController.dispose();
recoveringProgressController.dispose();
streamController.close();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Setting up your Twake',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
const SizedBox(height: 8),
Text(
'Setting up requires extra time so, please, be patient.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
const SizedBox(height: 8),
LinearProgressIndicator(
value: loginSSOProgressController.value,
semanticsLabel: loginSSOProgress,
),
const SizedBox(height: 8),
LinearProgressIndicator(
value: backupProgressController.value,
semanticsLabel: backupProgress,
),
const SizedBox(height: 8),
LinearProgressIndicator(
value: recoveringProgressController.value,
semanticsLabel: recoveringProgress,
),
],
),
),
);
}
}
25 changes: 25 additions & 0 deletions lib/utils/dialog/twake_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';

import 'package:fluffychat/utils/dialog/stream_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/twake_app.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -54,6 +57,28 @@ class TwakeDialog {
);
}

static void showStreamDialogFullScreen({
required Future Function() future,
required Function(StreamDialogState) listen,
}) async {
final twakeContext = TwakeApp.routerKey.currentContext;
if (twakeContext == null) {
Logs().e(
'TwakeLoadingDialog()::showStreamDialogFullScreen - Twake context is null',
);
}
await showDialog(
context: twakeContext!,
builder: (context) => StreamDialogBuilder(
future: future,
listen: listen,
),
barrierDismissible: true,
barrierColor: Colors.white,
useRootNavigator: false,
);
}

static Future<bool?> showDialogFullScreen({
required Widget Function() builder,
}) {
Expand Down

0 comments on commit b681ece

Please sign in to comment.