mirror of
https://github.com/Auties00/Reboot-Launcher.git
synced 2026-01-14 11:39:17 +01:00
Release 9.2.0
This commit is contained in:
79
gui/lib/src/messenger/abstract/info_bar.dart
Normal file
79
gui/lib/src/messenger/abstract/info_bar.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:reboot_launcher/src/page/pages.dart';
|
||||
|
||||
const infoBarLongDuration = Duration(seconds: 4);
|
||||
const infoBarShortDuration = Duration(seconds: 2);
|
||||
const _height = 64.0;
|
||||
|
||||
InfoBarEntry showRebootInfoBar(dynamic text, {
|
||||
InfoBarSeverity severity = InfoBarSeverity.info,
|
||||
bool loading = false,
|
||||
Duration? duration = infoBarShortDuration,
|
||||
void Function()? onDismissed,
|
||||
Widget? action
|
||||
}) {
|
||||
final overlay = _buildOverlay(text, action, loading, severity);
|
||||
final overlayEntry = InfoBarEntry(overlay: overlay, onDismissed: onDismissed);
|
||||
if(duration != null) {
|
||||
Future.delayed(duration)
|
||||
.then((_) => WidgetsBinding.instance.addPostFrameCallback((timeStamp) => overlayEntry.close()));
|
||||
}
|
||||
return overlayEntry;
|
||||
}
|
||||
|
||||
Widget _buildOverlay(text, Widget? action, bool loading, InfoBarSeverity severity) => ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: double.infinity,
|
||||
minHeight: _height
|
||||
),
|
||||
child: Mica(
|
||||
elevation: 1,
|
||||
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: const EdgeInsets.only(
|
||||
top: 8.0,
|
||||
bottom: 2.0,
|
||||
right: 6.0
|
||||
),
|
||||
child: ProgressBar(),
|
||||
) : const SizedBox()
|
||||
),
|
||||
severity: severity
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
class InfoBarEntry {
|
||||
final Widget overlay;
|
||||
final void Function()? onDismissed;
|
||||
|
||||
InfoBarEntry({required this.overlay, required this.onDismissed}) {
|
||||
final context = pageKey.currentContext;
|
||||
if(context != null) {
|
||||
infoBarAreaKey.currentState?.insertChild(overlay);
|
||||
}
|
||||
}
|
||||
|
||||
bool close() {
|
||||
final result = infoBarAreaKey.currentState?.removeChild(overlay) ?? false;
|
||||
if(result) {
|
||||
onDismissed?.call();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user