Skip to content

Commit

Permalink
feat: autocomplete textfield implemented and migration from simple si…
Browse files Browse the repository at this point in the history
…ngleton to GetxControllers
  • Loading branch information
AritraBiswas9788 committed Jun 24, 2024
1 parent 02cfdaf commit 5bc4b28
Show file tree
Hide file tree
Showing 23 changed files with 481 additions and 500 deletions.
Binary file added assets/icons/api_indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/ssh_indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
203 changes: 0 additions & 203 deletions lib/components/AutoCompleteLocationField.dart

This file was deleted.

154 changes: 154 additions & 0 deletions lib/components/autocomplete_locationfield.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@

import 'package:flutter/material.dart';
import 'package:super_liquid_galaxy_controller/utils/autocomplete_controller.dart';
import 'package:super_liquid_galaxy_controller/utils/galaxy_colors.dart';

import '../data_class/PlaceSuggestionResponse.dart';

class AutoCompleteLocationField extends StatefulWidget {
AutoCompleteLocationField(
{super.key,
required this.hintText,
required this.labelText,
required this.iconData,
required this.textInputType,
required this.isPassword,
required this.autocompleteController,
required this.seekTo,
this.controller,
this.buttonAction,
this.endIcon,
this.fillColor,
this.textColor});

String hintText;
String labelText;
IconData iconData;
TextInputType textInputType;
bool isPassword;
TextEditingController? controller;
VoidCallback? buttonAction;
IconData? endIcon;
Color? fillColor;
Color? textColor;
AutocompleteController autocompleteController;
Function(Features) seekTo;

@override
State<AutoCompleteLocationField> createState() =>
_AutoCompleteLocationFieldState();
}

class _AutoCompleteLocationFieldState extends State<AutoCompleteLocationField> {
bool _obscureText = false;
TextEditingController textController = TextEditingController();

@override
void initState() {
super.initState();
_obscureText = widget.isPassword;
}

@override
Widget build(BuildContext context) {
return Autocomplete<Features>(
fieldViewBuilder: (BuildContext context, TextEditingController controller,
FocusNode focusNode, VoidCallback onFieldSubmitted) {
textController = controller;
return TextField(
obscureText: _obscureText,
focusNode: focusNode,
onTap: onFieldSubmitted,
controller: controller,
decoration: InputDecoration(
hintText: widget.hintText,
hintStyle:
TextStyle(fontSize: 20, color: Colors.grey.withOpacity(0.4)),
contentPadding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 20),
prefixIcon: Padding(
padding: const EdgeInsets.all(12.0),
child: Icon(
widget.iconData,
color: widget.textColor ?? Colors.grey,
size: 50.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: const BorderSide(
color: Colors.grey,
style: BorderStyle.solid,
width: 2.5)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: const BorderSide(
color: GalaxyColors.blue,
style: BorderStyle.solid,
width: 2.5)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: const BorderSide(
color: Colors.grey,
style: BorderStyle.solid,
width: 2.5)),
fillColor: widget.fillColor ?? Colors.transparent,
filled: widget.fillColor == null ? false : true,
label: Text(widget.labelText),
focusColor: Colors.grey,
floatingLabelBehavior: FloatingLabelBehavior.always,
labelStyle: const TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.bold),
alignLabelWithHint: true,
suffixIcon: (Material(
color: Colors.transparent,
child: InkWell(
borderRadius: BorderRadius.circular(30),
onTap: (){
textController.clear();
},
child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: Icon(
Icons.cancel_rounded,
color: Colors.red,
size: 40.0,
),
),
)))),
style:
TextStyle(fontSize: 25, color: widget.textColor ?? Colors.grey),
maxLines: 1,
minLines: 1,
keyboardType: widget.textInputType,
);
},
displayStringForOption: (option) =>
'${option.properties?.name} - ${option.properties?.city}',
optionsBuilder: (TextEditingValue textEditingValue) async {
if (textEditingValue.text.isEmpty) {
return widget.autocompleteController.lastOptions;
}
setState(() {
widget.autocompleteController.networkError = false;
});
//debug
print("Request sent: ${textEditingValue.text}");
final Iterable<Features>? options = await widget.autocompleteController
.debouncedSearch(textEditingValue.text);
if (options == null) {
return widget.autocompleteController.lastOptions;
}
widget.autocompleteController.lastOptions = options;
print("suggestion: ${options.length}");
return options;
},
onSelected: (Features selection) {
debugPrint('You just selected ${selection.properties?.name}');
widget.seekTo(selection);
},
);
}
}
2 changes: 1 addition & 1 deletion lib/components/kml_elements/linestring.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:super_liquid_galaxy_controller/components/kml_elements/placemark
import 'package:super_liquid_galaxy_controller/data_class/coordinate.dart';
import 'package:super_liquid_galaxy_controller/utils/galaxy_colors.dart';

import '../../data_class/KmlElement.dart';
import '../../data_class/kml_element.dart';
import '../coordinate_field.dart';

class LineStringElement extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/kml_elements/placemark.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:super_liquid_galaxy_controller/data_class/KmlElement.dart';
import 'package:super_liquid_galaxy_controller/data_class/kml_element.dart';
import 'package:super_liquid_galaxy_controller/data_class/coordinate.dart';
import 'package:get/get.dart';
import '../coordinate_field.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/components/kml_elements/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:super_liquid_galaxy_controller/components/kml_elements/placemark
import 'package:super_liquid_galaxy_controller/data_class/coordinate.dart';
import 'package:super_liquid_galaxy_controller/utils/galaxy_colors.dart';

import '../../data_class/KmlElement.dart';
import '../../data_class/kml_element.dart';
import '../coordinate_field.dart';

class PolygonElement extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/components/navisland.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class NavIsland extends StatelessWidget {
Material(
color: Colors.transparent,
child: InkWell(
onTap: (){print("blah");},
onTap: (){},
borderRadius: BorderRadius.circular(15),
child: Container(
width: width*0.34,
Expand Down
Loading

0 comments on commit 5bc4b28

Please sign in to comment.