Card and ListView on single screen - flutter

I have a dropdown box and a listview below it on a screen.
On selection of a item in dropdownbox, the list view gets populated with multiple cards. As such the logic is working, but somehow having issues with the scroll configuration.
I have the main parent widget like this:
Widget build(BuildContext context) {
return Column(
children: <Widget>[locationDropdown(), showPackages(plansLoading)],
);
}
The locationDropDown() function returns a card widget with dropdown in it.
showPackages(plansLoading) returns a ListView widget whose code is like
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
return Card(
color: Colors.transparent,
child: Column(
children: <Widget>[
///...
],
),
);
)
Requirement is to keep the card in the loationDropdown() widget fixed at its place and the cards generated in showPackages's listview be scrolled.
This is the output I am getting, I am unable to scroll.
This functionality is not working. Where am I going wrong?

you can used SafeArea Widget or use Expanded widget before Listview.
ex.
Column (
children: <Widget>[
new TextField(
decoration: new InputDecoration(
labelText: "Search something"
),
Expanded(
ListView(),
),
]
)

Related

I want to disable a widget if there is no data in the futurebuilder

i have a pageview with widget1 and widget2 both use a futurebuilder i want to disable widget2 and swipe if there is no data in his futurebuilder
I have two pages 1 and 2. I want to stay only on page 1 and also no swipe if in page2 there is no data in the futurebuilder –
the problem is if there is no data in widget1 the pageview becomes empty
controller: controller,
scrollDirection: Axis.vertical,
child: Column(
children: <Widget>[
SizedBox(
child: PageView(
scrollDirection: Axis.horizontal
children: [
Widget1(),
Widget2()
]),
),
Widget3(),
Widget4(),
widget5(),
widget6(),
],
),
),
use the visibility widget and add a condition to show your widget.
Visibility(visible: <YOUR CONDITION>, child: Container()),

Set Containers array into Stack view Flutter

I am trying to display a ListView Horizontal n times in Stack or Row. But in the end all the ListViews are piled up instead shows one by one from top to bottom.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Prueba para trabajar en el proyecto"),
),
body: Stack(
children: <Widget>[
_crearLista(),
_crearLista(),
_crearLista(),
_crearLista(),
_crearLista(),
//_crearLoading(),
],
),
);
}
Widget _crearLista() {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Flexible(
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.25,
decoration: BoxDecoration(),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _listaNumeros.length,
itemBuilder: (BuildContext context, int index) {
//return image
},
controller: _scrollController,
),
),
)
],
),
);
}
Any suggestions? please. I want to show all the LsitViews.
A Stack widget puts its children above each other (overlapped or piled up) at the left top corner of the stack by default. Unless you position each child using a Positioned or Align widget. To have all the children one below the other (starting from top of the screen towards bottom), you need to use a Column instead of Stack.
Stack children behave like layers, one covers second, etc.
If you want one child exactly below another, there is ListView and Column

ListView inside Column throws error 'Vertical viewport was given unbounded height'

My question seems to be a duplicate of ListView inside Column causes 'Vertical viewport was given unbounded height' but the solution to add an Expanded or Flexible widget around the ListView doesn't work at all. It still throws the same error: Vertical viewport was given unbounded height.
var data = ['a','b','c','d'];
Column(
children: <Widget>[
ListView.builder(
itemCount: data.length,
itemBuilder: (ctx, i) {
return Row(
children: <Widget>[
Text(data[i], style: TextStyle(fontSize: 24 * Rat.rat, color: Colors.white)),
],
);
},
),
],
);
Obviously it can easily be fixed by adding a container around the ListView with a fixed height but there should be no need for that, I want it to be dynamically sized.
UPDATE:
Try something like this:
class Esempio1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("WAKAWAKA"),
),
body: Container(
child: Column(
children: <Widget>[
Text("eg1"),
Text("eg2"),
Text("eg3"),
Expanded(
child: ListView.builder(
itemCount: 20,
itemBuilder: (ctx,i){
return ListTile(title: Text("aaaaaa$i"),);
},
),
)
],
),
),
);
}
}
I just tried this code and it should do what you want.
The OP actually had the block of code posted contained inside another Column, that's why the Expanded wasn't working as it should when wrapped around the ListView. Wrapping the Column inside another Expanded solved the problem and made it all work as expected.
How about wrapping ListView builder in SingleChildScrollView and setting up its physics to
physics: NeverScrollableScrollPhysics(),

Flutter Dismissible causing unnecesary redraw when pushed navigated on top

I'm making an app with Flutter, and I found a weird behaviour that I got to reproduce in a small demo: https://pastebin.com/ZJd2fnHK
The objective is to have a TextField that when in focus should select the whole text. I achieved this with a FocusNode.
Everything was working fine, until I set a Dismissible widget to remove items from a list. For some reason (probably drawing ones) the whole page has a rebuild and the focusnode state is lost.
It's very interesting since the issue only happens when the widget is within a page that has being pushed by the navigator. The same Widget works fine in the root Page.
The Widget is the following:
Widget build(BuildContext context) {
textControllerA.text = "Hello";
textControllerB.text = "World";
return Column(children: [
Dismissible(
key: Key("potatoes"),
onDismissed: (direction) {},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
child: TextField(
focusNode: focusNodeA,
controller: textControllerA,
),
padding: EdgeInsets.all(20),
),
],
),
),
Padding(
child: TextField(
focusNode: focusNodeB,
controller: textControllerB,
),
padding: EdgeInsets.all(20),
),
]);
}
Maybe I should try to store the focus' state in state, but that'd have some overhead. Or maybe (possibly) I'm doing something very wrong, in which case I would love to have some guidance.
Cheers
You should use StatefulWidget and call setState
onDismissed: (direccion) {
setState(() {
...
});

Adding both vertical and horizontal scrolling to ListView

How can I make the Rows inside a vertical ListView, scrollable horizontally.
This is what my app looks like:
I want the user to be able to scroll the ListView both horizontally (to see the contents of the Row) and vertically to see new list items. This behavior is like how you would scroll a DataTable in Flutter:
Here is the build method (based on the Flutter project template):
#override
Widget build(BuildContext context) {
final List<String> rows = [
"This is a row with some very long text ... That goes on and on",
"This class is the configuration for the state.",
"case the title) provided by the parent (in this case the App widget) and",
"always marked \"final\"."
];
return Scaffold(
appBar: AppBar(title: Text("ListView")),
body: ListView(
padding: EdgeInsets.all(10),
children: <Widget>[
for (final String row in rows)
Row(
children: <Widget>[Text(row)],
)
],
),
);
}
Update: Wrapping the Text in Expanded doesn't work as it causes the text to wrap onto multiple lines. I want the text to remain on a single line.
Finally
After a deep search found this finally
#override
Widget build(BuildContext context) {
return new Scaffold(
body: new SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new SizedBox(
width: 1000.0,
child: new ListView.builder(
itemBuilder: (BuildContext context, int i) {
return new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: new List.generate(5, (int j) {
return new Text("$i,$j");
}),
);
},
),
),
),
);
}
Original source Vote up his answer too