Newer
Older
import 'package:flutter/material.dart';
import 'package:app/server_requests/init_state.dart';
import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart';
import '../widgets/main_layout.dart';
import '../utils/custom_search_delegate.dart';
class DefaultPage extends StatefulWidget {
const DefaultPage({Key? key}) : super(key: key);
@override
_DefaultPageState createState() => _DefaultPageState();
}
class _DefaultPageState extends State<DefaultPage> {
late Timer _timer;
bool serverConnection = true;
final backgroundColor = Colors.black87;
@override
void dispose() {
_timer.cancel();
super.dispose();
}
Future<void> _handleRefresh() async {
return await initialiseState(false);
@override
Widget build(BuildContext context) {
leading: IconButton(
icon: const Icon(
Icons.menu,
color: Colors.white54
),
onPressed: () {
// Not implemented
},
),
title: Text(
selectedLake, // Display name of current map
style: regTextStyleBig,
),
actions: [
IconButton(
icon: const Icon(
Icons.search,
color: Colors.white54
),
onPressed: () {
showSearch( // Fetch new relation and measurements on search
delegate: CustomSearchDelegate((String result) {
// Make request only if the selected lake is different from the current selected lake
if (result != selectedLake) {
setState(() {
selectedLake = result;
// NB update lastLake persistent variable
color: backgroundColor,
height: 100,
backgroundColor: Colors.grey[600],
onRefresh: _handleRefresh,
animSpeedFactor: 3,
showChildOpacityTransition: false,
child: Container( // Return main container with map and stats widget
color: const Color(0xff151515),
child: ListView(
children: [
MapContainerWidget(
measurements: selectedMeasurements,
relation: selectedRelation,
serverConnection: serverConnection,
),
],
),
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
}
void fetchNewLake(BuildContext context) {
showDialog(
context: context,
barrierDismissible: false, // Prevent dismissal by user
builder: (BuildContext dialogContext) {
bool initialized = false;
// Display CircularProgressIndicator
Future.delayed(const Duration(milliseconds: 500), () {
if (!initialized) {
showDialog(
context: dialogContext,
builder: (BuildContext _) => const Center(
child: CircularProgressIndicator(),
),
);
}
});
initialiseState(false).then((_) {
// Mark initialization as complete
initialized = true;
Navigator.of(dialogContext, rootNavigator: true).pop();
});
// Return a placeholder widget for the dialog
return const SizedBox.shrink();
},
);
}