mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-13 11:12:23 +01:00
Final version
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:reboot_launcher/src/page/home_page.dart';
|
||||
import 'package:reboot_launcher/src/page/abstract/page_type.dart';
|
||||
import 'package:reboot_launcher/src/page/pages.dart';
|
||||
import 'package:sync/semaphore.dart';
|
||||
|
||||
Semaphore _semaphore = Semaphore();
|
||||
HashMap<int, OverlayEntry?> _overlays = HashMap();
|
||||
|
||||
void restoreMessage(int lastIndex) {
|
||||
removeMessage(lastIndex);
|
||||
var overlay = _overlays[pageIndex.value];
|
||||
void restoreMessage(int pageIndex, int lastIndex) {
|
||||
removeMessageByPage(lastIndex);
|
||||
var overlay = _overlays[pageIndex];
|
||||
if(overlay == null) {
|
||||
return;
|
||||
}
|
||||
@@ -17,48 +18,62 @@ void restoreMessage(int lastIndex) {
|
||||
Overlay.of(pageKey.currentContext!).insert(overlay);
|
||||
}
|
||||
|
||||
void showInfoBar(dynamic text, {InfoBarSeverity severity = InfoBarSeverity.info, bool loading = false, Duration? duration = snackbarShortDuration, Widget? action}) {
|
||||
OverlayEntry showInfoBar(dynamic text,
|
||||
{RebootPageType? pageType,
|
||||
InfoBarSeverity severity = InfoBarSeverity.info,
|
||||
bool loading = false,
|
||||
Duration? duration = snackbarShortDuration,
|
||||
Widget? action}) {
|
||||
try {
|
||||
_semaphore.acquire();
|
||||
var index = pageIndex.value;
|
||||
removeMessage(index);
|
||||
var overlay = showSnackbar(
|
||||
pageKey.currentContext!,
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Mica(
|
||||
child: InfoBar(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if(text is Widget)
|
||||
text,
|
||||
if(text is String)
|
||||
Text(text),
|
||||
if(action != null)
|
||||
action
|
||||
],
|
||||
var index = pageType?.index ?? pageIndex.value;
|
||||
removeMessageByPage(index);
|
||||
var overlay = OverlayEntry(
|
||||
builder: (context) => Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: 12.0,
|
||||
left: 12.0,
|
||||
bottom: pagesWithButtonIndexes.contains(index) ? 72.0 : 16.0
|
||||
),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 1000
|
||||
),
|
||||
child: Mica(
|
||||
child: InfoBar(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if(text is Widget)
|
||||
text,
|
||||
if(text is String)
|
||||
Text(text),
|
||||
if(action != null)
|
||||
action
|
||||
],
|
||||
),
|
||||
isLong: false,
|
||||
isIconVisible: true,
|
||||
content: SizedBox(
|
||||
width: double.infinity,
|
||||
child: loading ? const Padding(
|
||||
padding: EdgeInsets.only(top: 8.0, bottom: 2.0),
|
||||
child: ProgressBar(),
|
||||
) : const SizedBox()
|
||||
),
|
||||
severity: severity
|
||||
),
|
||||
isLong: false,
|
||||
isIconVisible: true,
|
||||
content: SizedBox(
|
||||
width: double.infinity,
|
||||
child: loading ? const Padding(
|
||||
padding: EdgeInsets.only(top: 8.0, bottom: 2.0),
|
||||
child: ProgressBar(),
|
||||
) : const SizedBox()
|
||||
),
|
||||
severity: severity
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
margin: EdgeInsets.only(
|
||||
right: 12.0,
|
||||
left: 12.0,
|
||||
bottom: index == 0 || index == 1 || index == 3 || index == 4 ? 72.0 : 16.0
|
||||
),
|
||||
duration: duration
|
||||
)
|
||||
);
|
||||
if(index == pageIndex.value) {
|
||||
Overlay.of(pageKey.currentContext!).insert(overlay);
|
||||
}
|
||||
_overlays[index] = overlay;
|
||||
if(duration != null) {
|
||||
Future.delayed(duration).then((_) {
|
||||
@@ -73,17 +88,24 @@ void showInfoBar(dynamic text, {InfoBarSeverity severity = InfoBarSeverity.info,
|
||||
});
|
||||
});
|
||||
}
|
||||
return overlay;
|
||||
}finally {
|
||||
_semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
void removeMessage(int index) {
|
||||
void removeMessageByPage(int index) {
|
||||
var lastOverlay = _overlays[index];
|
||||
if(lastOverlay != null) {
|
||||
removeMessageByOverlay(lastOverlay);
|
||||
_overlays[index] = null;
|
||||
}
|
||||
}
|
||||
|
||||
void removeMessageByOverlay(OverlayEntry? overlay) {
|
||||
try {
|
||||
var lastOverlay = _overlays[index];
|
||||
if(lastOverlay != null) {
|
||||
lastOverlay.remove();
|
||||
_overlays[index] = null;
|
||||
if(overlay != null) {
|
||||
overlay.remove();
|
||||
}
|
||||
}catch(_) {
|
||||
// Do not use .isMounted
|
||||
|
||||
Reference in New Issue
Block a user