I have a FutureBuilder widget which retrieves chats (or rather updates) from the server and displays them. Here is the code:
Future<List<Chat>> fetchChats(http.Client client, String providerUUID) async {
returns List<Chat>..
}
class ProviderChats extends StatelessWidget {
final List<Chat> chats;
final String providerUUID;
ProviderChats({this.chats, this.providerUUID});
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Chat>>(
future: fetchChats(http.Client(), providerUUID),
builder: (context, snapshot){
if(snapshot.hasError) print(snapshot.error);
return snapshot.hasData ?
ChatsListWidgetClass(chats: snapshot.data) :
Center(child: CircularProgressIndicator());
},
);
}
}
class ChatsListWidgetClass extends StatelessWidget {
final List<Chat> chats;
ChatsListWidgetClass({this.chats});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: chats.length,
itemBuilder: (context, index) {
return Card(
elevation: 10.0,
child: Column(
children: <Widget>[
Text(
chats[index].message,
),
Text(
chats[index].createdAt,
),
],
),
);
},
);
}
}
It looks something like this:
At the bottom of the screen, I want to show a TextField with a Send button (just like what we see on chat screens). But I am unable to accommodate my ListView.builder inside a Column.
Is there a way to make the list occupy 80% of the vertical space from top and make the send textfield occupy the bottom 20%. Basically like a chat application window.
You can use Expanded with a custom weight to fill a column with a percentage
Column(
children: <Widget>[
Expanded(
flex: 8,
child: Container(
color: Colors.red,
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.blue,
),
),
],
);
Using Remi's response this worked for me
return new Scaffold(
appBar: new AppBar(
title: new Text("Home Page"),
),
body: new Builder(
builder: (BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
flex: 8,
child: futureBuilder,
),
Expanded(
flex: 2,
child: Text("hello"),
),
],
);
}
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With