import 'dart:async'; import 'dart:convert'; 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 '../consts.dart'; import '../widgets/main_layout.dart'; import '../widgets/choropleth_map.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; bool dialogShown = false; final backgroundColor = Colors.black87; @override void dispose() { _timer.cancel(); super.dispose(); } Future<void> _handleRefresh() async { return await initialiseState(false); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: backgroundColor, appBar: AppBar( backgroundColor: backgroundColor, 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 context: context, delegate: CustomSearchDelegate((String result) { // Make request only if the selected lake is different from the current selected lake if (result != selectedLake) { initialiseState(false); setState(() { print("SetState called!"); selectedLake = result; // NB update lastLake persistent variable }); } }), ); }, ), ], ), body: LiquidPullToRefresh( 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: selectedMarkerList, relation: selectedRelation, serverConnection: serverConnection, ), ], ), ), ), ), ); } }