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

added feedback once a event has been created

parent a0c24c69
Branches
Tags
No related merge requests found
......@@ -25,6 +25,9 @@ class _AddEventPageState extends State<AddEvent> {
final prefs = SharedPreferences.getInstance(); // Is async
var database = DatabaseInstance();
late OverlayEntry _overlayEntry; //For event creation success notifications
late Timer _overlayCloseTimer;
Future startGNSS() async {
final EventStoreInstance eventStore = EventStoreInstance();
debugPrint("Check Location Permission");
......@@ -99,6 +102,12 @@ class _AddEventPageState extends State<AddEvent> {
debugPrint('Canceling location stream failed');
}
try {
_overlayEntry.remove();
}catch(e){
debugPrint('Dispose error on overlay remove: ' + e.toString());
}
/*Async update current event configuration to shared preferences*/
final EventStoreInstance event = EventStoreInstance();
event.storeToSharedPrefs();
......@@ -169,56 +178,74 @@ class _AddEventPageState extends State<AddEvent> {
return false;
}
void _showAddSuccessOverlay(BuildContext context) async {
// Declaring and Initializing OverlayState
// and OverlayEntry objects
Future<void> _showResultPopup(BuildContext context, String text, bool error) async {
OverlayState? overlayState = Overlay.of(context);
OverlayEntry overlayEntry;
overlayEntry = OverlayEntry(builder: (context) {
// You can return any widget you like
// here to be displayed on the Overlay
return Positioned(
top: MediaQuery.of(context).padding.top,
right: MediaQuery.of(context).padding.right,
try {
_overlayEntry.remove(); // Allow only one Overlay Popup at a time
}catch(e){
debugPrint('Overlay already removed, during dispose: ' + e.toString());
}
_overlayEntry = OverlayEntry(builder: (context) {
Color backGroundColor;
Color textColor;
if (error == true){
backGroundColor = Colors.redAccent; //Style for error message
textColor = Colors.black;
}
else {
backGroundColor = Colors.greenAccent; //Style for notification
textColor = Colors.black;
}
return Stack(
alignment: Alignment.center,
children: [
Positioned(
// Position at 10% of height from bottom
bottom: MediaQuery.of(context).size.height * 0.1,
child: Material(
color: Colors.transparent,
child: Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.all(3.0), //a view pixel space to top and right
borderRadius: BorderRadius.circular(8.0),
color: backGroundColor, //Some transparency remains
child: Container(
decoration: ShapeDecoration(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0)
)
),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Created Event!',
//style: TextStyle(
// color: Colors.black, fontWeight: FontWeight.bold),
),
padding: const EdgeInsets.all(5.0), // Space between Text and Bubble
width: MediaQuery.of(context).size.width * 0.95,
child: TextFormField(
minLines: 1,
maxLines: 5,
readOnly: true,
autofocus: false,
enabled: false,
style: TextStyle(color: textColor),
controller: TextEditingController(
text: text,
),
),
),
),
),
],
);
});
// Inserting the OverlayEntry into the Overlay
overlayState?.insert(overlayEntry);
// Awaiting for 3 seconds
await Future.delayed(const Duration(seconds: 3));
overlayState?.insert(_overlayEntry);
// Removing the OverlayEntry from the Overlay
overlayEntry.remove();
try {
_overlayCloseTimer.cancel(); // Kill old timers
}catch(e){
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> _storeCurrentEvent(BuildContext context) async {
final EventStoreInstance event = EventStoreInstance();
......@@ -230,7 +257,8 @@ class _AddEventPageState extends State<AddEvent> {
_addButtonEnabled = true; //Activate button for add more events
setState(() {});
_showAddSuccessOverlay(context); //Show pop up to indicated adding event succeeded.
//_showAddSuccessOverlay(context); //Show pop up to indicated adding event succeeded.
_showResultPopup(context, "Successfully created Event !", false );
//Update timestamp in UI
var date = DateTime.now().toUtc();
......
......
......@@ -28,13 +28,10 @@ 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 = '';
TextStyle _statusStyle = const TextStyle(color: Colors.black);
Future<void> dumpToFile(BuildContext context) async{
var date = DateTime.now().toUtc();
......@@ -73,29 +70,24 @@ class _MyHomePageState extends State<Configuration> {
}
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 at a time
}catch(e){
debugPrint('Overlay already removed, during dispose: ' + e.toString());
}
_overlayEntry = OverlayEntry(builder: (context) { //TODO: kill old async delay as this closes the pop up after the remaining wait time.
_overlayEntry = OverlayEntry(builder: (context) {
Color backGroundColor;
Color textColor;
if (error == true){
backGroundColor = Colors.redAccent; //This is a error message display red!
backGroundColor = Colors.redAccent; //Style for error message
textColor = Colors.black;
}
else {
backGroundColor = Colors.greenAccent; //This is a normal message display green!
backGroundColor = Colors.greenAccent; //Style for notification
textColor = Colors.black;
}
// You can return any widget you like
// here to be displayed on the Overlay
return Stack(
alignment: Alignment.center,
children: [
......@@ -234,7 +226,7 @@ class _MyHomePageState extends State<Configuration> {
if(_initError == true){
_initError = false;
_showDelayed(context, _status, true); //NOTE: Dirty hack with delay. TODO: do properly but how?
_showDelayed(context, _status, true); //NOTE: Dirty hack with delay. Stack error without delay. Why?
}
return Scaffold(
......@@ -321,12 +313,6 @@ class _MyHomePageState extends State<Configuration> {
}
if (snapshot.hasError) {
debugPrint('Some error happened: ' + snapshot.error.toString());
//if(_initError == true){
// _initError = false;
// _showDelayed(context, _status, true); //TODO: opening a popup does not work properly from here.
//}
return const CircularProgressIndicator();
}
else{
......
......
......@@ -246,7 +246,7 @@ class _ViewEvents extends State<ViewEvents> {
DataCell(
TextFormField(
readOnly: true,
initialValue: event.elevation,
initialValue: event.elevation, //TODO: show only 2 digits after decimal point. toStringAsFixed(1),
onFieldSubmitted: (val) {
event.elevation = val; //Update Database
},
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment