import 'dart:convert';
import 'package:condomini/condominio.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(const MyHomePage());
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<StatefulWidget> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Condominio> condomini = [];
@override
void initState() {
var url = Uri.parse('http://www.ixee.it/index.php/flutter/getcondomini');
http.get(url).then((response) => setState(() {
condomini = List<Condominio>.from(
jsonDecode(response.body)['condomini']?.map(
(mappa) => Condominio.fromMap(mappa),
),
);
}));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("STEB"),
),
body: Column(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
horizontal: 10,
),
child: Row(
children: <Widget>[
Flexible(
child: TextField(
decoration: InputDecoration(
contentPadding:
EdgeInsets.symmetric(vertical: 20, horizontal: 10),
hintText: "Inserisci via",
hintStyle: TextStyle(color: Colors.blue, fontSize: 20),
isDense: true, // Added this
),
),
),
SizedBox(
width: 10,
),
ElevatedButton(
onPressed: () {},
child: Text("CERCA"),
),
],
),
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: condomini.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(condomini[index].nome),
subtitle: Text(condomini[index].indirizzo),
trailing: Icon(Icons.arrow_drop_up_rounded),
);
}),
)
],
),
);
}
}
I have this code where I need to create an android app where I will have a fixed Textfield where I can write the street of a building. The list of buildings complete with street and name, are taken from a request to a server with a response to a json file. What I need to be able to do is to be able to select a street in the building and automatically enter it in the fixed text field at the top of the page.