Error notifier

This commit is contained in:
2024-09-02 21:20:30 +08:00
parent ddeda2ce23
commit ee2633db52
18 changed files with 183 additions and 73 deletions

View File

@@ -1,12 +1,43 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rhythm_box/platform.dart';
import 'package:rhythm_box/providers/error_notifier.dart';
import 'package:window_manager/window_manager.dart';
class SystemShell extends StatelessWidget {
class SystemShell extends StatefulWidget {
final Widget child;
const SystemShell({super.key, required this.child});
@override
State<SystemShell> createState() => _SystemShellState();
}
class _SystemShellState extends State<SystemShell> {
late final ErrorNotifier _errorNotifier = Get.find();
StreamSubscription? _subscription;
@override
void initState() {
super.initState();
_subscription = _errorNotifier.showing.listen((value) {
if (value == null) {
ScaffoldMessenger.of(context).clearMaterialBanners();
} else {
ScaffoldMessenger.of(context).showMaterialBanner(value);
}
});
}
@override
void dispose() {
_subscription?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (PlatformInfo.isMacOS) {
@@ -21,12 +52,12 @@ class SystemShell extends StatelessWidget {
thickness: 0.3,
height: 0.3,
),
Expanded(child: child),
Expanded(child: widget.child),
],
),
);
}
return child;
return widget.child;
}
}