added comments and refactored code
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CustomMarker extends StatelessWidget {
|
||||
const CustomMarker({super.key, required this.onTap});
|
||||
final void Function() onTap;
|
||||
const CustomMarker({super.key, required void Function() onTap})
|
||||
: _onTap = onTap;
|
||||
|
||||
final void Function() _onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
onTap: _onTap,
|
||||
child: Icon(
|
||||
Icons.location_on_sharp,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
|
||||
@@ -6,11 +6,12 @@ class FloodStationListView extends StatelessWidget {
|
||||
const FloodStationListView(
|
||||
{super.key,
|
||||
required List<FloodStation> stations,
|
||||
required this.onItemTapped})
|
||||
: _stations = stations;
|
||||
required void Function(FloodStation) onItemTapped})
|
||||
: _onItemTapped = onItemTapped,
|
||||
_stations = stations;
|
||||
|
||||
final List<FloodStation> _stations;
|
||||
final void Function(FloodStation) onItemTapped;
|
||||
final void Function(FloodStation) _onItemTapped;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -23,7 +24,7 @@ class FloodStationListView extends StatelessWidget {
|
||||
final item = _stations.elementAt(index);
|
||||
return ListTile(
|
||||
isThreeLine: true,
|
||||
onTap: () => onItemTapped(item),
|
||||
onTap: () => _onItemTapped(item),
|
||||
title: Text(item.label),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -2,9 +2,14 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class LoadingNotifier extends StatelessWidget {
|
||||
const LoadingNotifier(
|
||||
{super.key, required this.onDismissed, required this.message});
|
||||
final void Function() onDismissed;
|
||||
final String message;
|
||||
{super.key,
|
||||
required void Function() onDismissed,
|
||||
required String message})
|
||||
: _onDismissed = onDismissed,
|
||||
_message = message;
|
||||
|
||||
final void Function() _onDismissed;
|
||||
final String _message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -26,11 +31,11 @@ class LoadingNotifier extends StatelessWidget {
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
Text(
|
||||
message,
|
||||
_message,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => onDismissed(),
|
||||
onPressed: () => _onDismissed(),
|
||||
icon: Icon(Icons.close),
|
||||
)
|
||||
],
|
||||
|
||||
@@ -5,14 +5,19 @@ import '../model/flood_station.dart';
|
||||
|
||||
class MapPopup extends StatelessWidget {
|
||||
const MapPopup(
|
||||
{super.key, required this.station, required this.onShowTapped});
|
||||
final FloodStation station;
|
||||
final Function() onShowTapped;
|
||||
{super.key,
|
||||
required FloodStation station,
|
||||
required dynamic Function() onShowTapped})
|
||||
: _onShowTapped = onShowTapped,
|
||||
_station = station;
|
||||
|
||||
final FloodStation _station;
|
||||
final Function() _onShowTapped;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(station.label),
|
||||
title: Text(_station.label),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -22,14 +27,14 @@ class MapPopup extends StatelessWidget {
|
||||
children: [
|
||||
Icon(Icons.home_outlined),
|
||||
Padding(padding: EdgeInsets.only(left: 8)),
|
||||
Text(station.town.isEmpty ? '-' : station.town),
|
||||
Text(_station.town.isEmpty ? '-' : _station.town),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.water),
|
||||
Padding(padding: EdgeInsets.only(left: 8)),
|
||||
Text(station.riverName.isEmpty ? '-' : station.riverName),
|
||||
Text(_station.riverName.isEmpty ? '-' : _station.riverName),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
@@ -37,8 +42,8 @@ class MapPopup extends StatelessWidget {
|
||||
Icon(Icons.calendar_month_outlined),
|
||||
Padding(padding: EdgeInsets.only(left: 8)),
|
||||
Text(
|
||||
station.dateOpened != null
|
||||
? intl.DateFormat.yMd().format(station.dateOpened!)
|
||||
_station.dateOpened != null
|
||||
? intl.DateFormat.yMd().format(_station.dateOpened!)
|
||||
: '-',
|
||||
),
|
||||
],
|
||||
@@ -51,7 +56,7 @@ class MapPopup extends StatelessWidget {
|
||||
child: Text('dismiss'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: onShowTapped,
|
||||
onPressed: _onShowTapped,
|
||||
child: Text('show'),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -9,28 +9,28 @@ class StationFilter extends StatefulWidget {
|
||||
}
|
||||
|
||||
class StationFilterState extends State<StationFilter> {
|
||||
TextEditingController filterController = TextEditingController();
|
||||
final TextEditingController _filterController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
controller: filterController,
|
||||
controller: _filterController,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
suffixIcon: Opacity(
|
||||
opacity: filterController.text.isEmpty ? 0 : 1,
|
||||
opacity: _filterController.text.isEmpty ? 0 : 1,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
filterController.clear();
|
||||
_filterController.clear();
|
||||
|
||||
widget.onChanged(filterController.text);
|
||||
widget.onChanged(_filterController.text);
|
||||
},
|
||||
icon: Icon(Icons.delete),
|
||||
),
|
||||
),
|
||||
label: Text('Filter'),
|
||||
),
|
||||
onChanged: (_) => widget.onChanged(filterController.text),
|
||||
onChanged: (_) => widget.onChanged(_filterController.text),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user