From 9f4b99c5f945a30ce5012f8e9f94a5c3eb816bbe Mon Sep 17 00:00:00 2001 From: Konstantin Kollar Date: Tue, 6 Sep 2022 12:53:53 +0200 Subject: [PATCH] Fixed bugs: overflows on location view, made location view scrollable --- .../add_location_by_search_form.dart | 6 ++- .../locations/add_location_form.dart | 41 ++++++++++--------- .../locations/manage_single_location.dart | 7 +++- lib/screens/locations.dart | 41 ++++++++++--------- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/lib/components/locations/add_location_by_search_form.dart b/lib/components/locations/add_location_by_search_form.dart index e501646..44abcb4 100644 --- a/lib/components/locations/add_location_by_search_form.dart +++ b/lib/components/locations/add_location_by_search_form.dart @@ -67,8 +67,12 @@ class _AddLocationBySearchFormState extends State { children: [_singleResult(name: "No result")], ); } + Iterable locationsToShow = _locations!; + if (locationsToShow.length > 3) { + locationsToShow = _locations!.getRange(0, 3); + } return Column(children: [ - for (LocationModel location in _locations!.getRange(0, 3)) + for (LocationModel location in locationsToShow) _singleResult(name: location.name, location: location) ]); } diff --git a/lib/components/locations/add_location_form.dart b/lib/components/locations/add_location_form.dart index fcbcef6..79fdead 100644 --- a/lib/components/locations/add_location_form.dart +++ b/lib/components/locations/add_location_form.dart @@ -45,26 +45,27 @@ class AddLocationsFormState extends State { return Form( key: _formKey, child: Column(children: [ - Flexible( - flex: 4, - child: TextFormField( - //Location Name - onSaved: (input) { - newLocationName = input; - }, - controller: locationFormController, - validator: ((value) { - if (value == null || value.isEmpty) { - return "Please enter a name for the new location"; - } - if (widget.savedLocations.contains(value)) { - return "Location name already in use"; - } - return null; - }), - decoration: const InputDecoration( - border: UnderlineInputBorder(), labelText: "Location Name"), - )), + // Flexible( + // flex: 4, + // child: + TextFormField( + //Location Name + onSaved: (input) { + newLocationName = input; + }, + controller: locationFormController, + validator: ((value) { + if (value == null || value.isEmpty) { + return "Please enter a name for the new location"; + } + if (widget.savedLocations.contains(value)) { + return "Location name already in use"; + } + return null; + }), + decoration: const InputDecoration( + border: UnderlineInputBorder(), labelText: "Location Name"), + ), Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ diff --git a/lib/components/locations/manage_single_location.dart b/lib/components/locations/manage_single_location.dart index 3a93f7c..2385454 100644 --- a/lib/components/locations/manage_single_location.dart +++ b/lib/components/locations/manage_single_location.dart @@ -13,8 +13,11 @@ class ManageSingleLocation extends StatelessWidget { child: Padding( padding: const EdgeInsets.all(10), child: Row(children: [ - Text(name, style: Theme.of(context).textTheme.headline5), - const Spacer(), + Expanded( + child: Padding( + padding: const EdgeInsets.only(right: 12), + child: Text(name, + style: Theme.of(context).textTheme.headline5))), GestureDetector( onTap: () => delete(name), child: const Icon(Icons.delete_sharp)) diff --git a/lib/screens/locations.dart b/lib/screens/locations.dart index 3a0c607..380eda0 100644 --- a/lib/screens/locations.dart +++ b/lib/screens/locations.dart @@ -37,26 +37,27 @@ class _LocationsState extends State { appBar: AppBar( title: const Text('Locations'), ), - body: Padding( - padding: const EdgeInsets.all(20), - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - for (String name in locations) - ManageSingleLocation(name: name, delete: deleteLocation), - ...[ - const SizedBox(height: 20), - const Text("Add location by search"), - AddLocationBySearchForm(saveNewLocation: saveNewLocation), - const SizedBox(height: 20), - const Text("Add location by coordinates"), - Flexible( - fit: FlexFit.loose, - child: AddLocationsForm( + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(20), + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + for (String name in locations) + ManageSingleLocation( + name: name, delete: deleteLocation), + ...[ + const SizedBox(height: 20), + const Text("Add location by search"), + AddLocationBySearchForm( + saveNewLocation: saveNewLocation), + const SizedBox(height: 20), + const Text("Add location by coordinates"), + AddLocationsForm( saveNewLocation: saveNewLocation, - savedLocations: locations)), - ], - ])))); + savedLocations: locations), + ], + ]))))); } }