Skip to content
Snippets Groups Projects
Commit a0c24c69 authored by Maximilian Betz's avatar Maximilian Betz
Browse files

notification popups done in configuration widget

parent 333b19ad
No related branches found
No related tags found
No related merge requests found
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
......@@ -27,6 +28,9 @@ class _MyHomePageState extends State<Configuration> {
final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
late OverlayEntry _overlayEntry;
bool _overlayActive = false;
late OverlayState _overlayState;
late Timer _overlayCloseTimer;
bool _initError = false;
String _status = '';
......@@ -63,29 +67,30 @@ class _MyHomePageState extends State<Configuration> {
}
}
Future<void> _showDelayed(BuildContext context, String text, bool error) async {
await Future.delayed(const Duration(milliseconds: 250));
_showResultPopup(context, text, error);
}
Future<void> _showResultPopup(BuildContext context, String text, bool error) async {
// Declaring and Initializing OverlayState
// and OverlayEntry objects
OverlayState? overlayState = Overlay.of(context);
try {
_overlayEntry.remove(); // Allow only one Overlay Popup
_overlayEntry.remove(); // Allow only one Overlay Popup
}catch(e){
debugPrint('Overlay already removed, during dispose: ' + e.toString());
}
_overlayEntry = OverlayEntry(builder: (context) { //:
_overlayEntry = OverlayEntry(builder: (context) { //TODO: kill old async delay as this closes the pop up after the remaining wait time.
Color backGroundColor;
Color textColor;
if (error == true){
//This is a error message display red!
backGroundColor = Colors.redAccent;
backGroundColor = Colors.redAccent; //This is a error message display red!
textColor = Colors.black;
}
else {
//This is a normal message display green!
backGroundColor = Colors.greenAccent;
backGroundColor = Colors.greenAccent; //This is a normal message display green!
textColor = Colors.black;
}
......@@ -121,18 +126,24 @@ class _MyHomePageState extends State<Configuration> {
);
});
// Inserting the OverlayEntry into the Overlay
overlayState?.insert(_overlayEntry);
// Awaiting for 5 seconds
await Future.delayed(const Duration(seconds: 5));
// Removing the OverlayEntry from the Overlay
try {
_overlayEntry.remove(); //NOTE: Is this a quick an dirty or a proper solution?
_overlayCloseTimer.cancel(); // Kill old timers
}catch(e){
debugPrint('Overlay already removed, during dispose: ' + e.toString());
debugPrint('Timer cancel error: ' + e.toString());
}
_overlayCloseTimer = Timer(
const Duration(seconds: 5),
() {
try {
_overlayEntry.remove(); // Allow only one Overlay Popup. NOTE: Is this a quick an dirty or a proper solution?
}catch(e){
debugPrint('Overlay already removed, during dispose: ' + e.toString());
}
},
);
}
Future<void> updateConfiguration(BuildContext context) async {
......@@ -221,6 +232,11 @@ class _MyHomePageState extends State<Configuration> {
final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
final EventStoreInstance events = EventStoreInstance();
if(_initError == true){
_initError = false;
_showDelayed(context, _status, true); //NOTE: Dirty hack with delay. TODO: do properly but how?
}
return Scaffold(
appBar: AppBar(
title: const Text('Configuration'),
......@@ -304,12 +320,12 @@ class _MyHomePageState extends State<Configuration> {
);
}
if (snapshot.hasError) {
debugPrint('Some error happened');
debugPrint('Some error happened: ' + snapshot.error.toString());
if(_initError == true){
_initError = false;
//_showResultPopup(context, _status, true); //TODO: opening a popup does not work properly from here.
}
//if(_initError == true){
// _initError = false;
// _showDelayed(context, _status, true); //TODO: opening a popup does not work properly from here.
//}
return const CircularProgressIndicator();
}
......@@ -319,17 +335,7 @@ class _MyHomePageState extends State<Configuration> {
}
),
const SizedBox(height: 70.0),
TextFormField(
minLines: 1,
maxLines: 5,
readOnly: true,
autofocus: false,
enabled: false,
style: _statusStyle,
controller: TextEditingController(
text: _status,
),
),
],
),
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment