How can I use 2 bodies in flutter - flutter

I’m getting an error message
“The argument for the named parameter ‘body’ was already specified.”

You can't. I'm not sure what you need to do. But here's a list of widgets and Codes that might help you achieve what you want:
Column widget :List widgets in a column
body: Column(
children: [
Container(),
Container(),
Container()
],
)
Stack widget :Stack widgets on top of each other
body: Stack(
children: [
Container(),
Container(),
Container()
],
)
PageView widget : Create pages that users can navigate to by swiping the screen left and right
body: PageView(
children: [
Container(),
Container(),
Container()
],
)

Related

Is it possible to insert GameWidget(game: SpaceShooterGame()) in a column Widget. (Flutter Flame)

Column(
children: [
GameWidget(game: SpaceShooterGame()),
I got following message
The following assertion was thrown during performLayout():
RenderConstrainedBox object was given an infinite size during layout.
How to do ?
I try may widget around GameWidget (row ,column ..)
none is working
You can use Expanded widget inside Column.
Column(
children: [
Expanded(
child: GameWidget(
game: SpaceShooterGame(),
),
),
],
)

Flutter: how to add anchored button at the bottom of a page after a ListView

This is my code until now, I would like to anchor the Material button to the bottom of the Screen, so I would like that my Column to take all the available space on the screen, I cannot use the Scaffold arguments like bottomsheet for this, since it is another widget and there is some separate logic that requires the button to be in the same place as the listView
Scaffold(
body: Column(children[
Container(),
Container(),
_myWidget(),
]));
Widget _myWidget(){
return Expanded(
child: Column(
children:[
Container(),
ListView.builder( /* more_code*/ ),
Align(
alignment: Alignment.bottomCenter,
child: MaterialButton(/* more_code */)
),],),
);
This is how the button is now, I want to anchor it to the bottom
Write with stack instead of column
Widget _myWidget(){
return Expanded(
child: Stack(
children:[
Container(),
ListView.builder( /* more_code*/ ),
Align(
alignment: Alignment.bottomCenter,
child: MaterialButton(/* more_code */)
),],),
);

How to place widget to the bottom inside Form widget?

I have widget:
Scaffold(
appBar: ...,
body: Form(
child: ListView(
children: [
...
ElevatedButton() // Save button
]
)
)
);
So, I want to place it to the bottom of the screen. I tried to place it inside Align widget but it doesn't work. Another thing is that I have ExpansionTile above and it can overflow the screen. In this case, there mustn't be any additional space between Activate and Save buttons. How to do it?
Use MainAxisAlignment.spaceBetween. Documentation:
Place the free space evenly between the children.
bool _hasExpansionTile = false;
Scaffold(
appBar: ...,
body: Column(mainAxisAlignment: _hasExpansionTile ? MainAxisAlignment.start : MainAxisAlignment.spaceBetween, /// Checking that the expansion tile is visible
children: [
Flexible(
child: Form(
child: Column(
children: [
...
],
),
),
),
ElevatedButton(onPressed: (){}, child: Text("Send")),
],
),
);
Of course you must use setState(), when you changing the value of the _hasExpansionTile property.
You can use Spacer()
Scaffold( appBar: ...,
body: Form(
child: ListView(
children: [
...
Spacer(),
ElevatedButton() // Save button
]
)
)
);

Flutter : How to place a Widget below fixed Centered Widget inside a Container

How to place a Widget below fixed Centered Widget inside a Container? I am using a GridView to show widgets horizontally. GridView item will have a Text Widget which has to be fixed at the Centered everytime in the screen. I have to place a Text widget below that Centered Widget.
Reference Screenshot:
Adding the build method code of the GridView item I have tried till now. But the Text Widget is not getting centered. The output I am getting. How to fix this part ?
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomText(
(dayModel?.date?.day ?? "").toString(),
AppTextStyle.Body,
customColor: _getColorBasedOnStyle(
dayModel.style,
),
),
Visibility(
visible: dayModel?.style == CalendarDayStyles.NOT_AVAILABLE,
child: CustomText(
Strings.no_slots_label,
AppTextStyle.SublineForCalendar,
customColor: AppColors.BLACK_20,
),
),
],
);
}
I believe the secret to doing this right is not only in how you build "6", but also in how you build "5" and "7".
E.g. you could build every one of them as column with 3 boxes on top of each other, pseudocode:
Column(
children: [
SizedBox(height: fixedHeight, child: empty)
SizedBox(height: fixedHeight, child: Text("5")) // or "6" or "7"
SizedBox(height: fixedHeihgt, child: empty) // or booking status
]
)
or other way of doing it if we have to avoid using fixedHeight is by using the Expanded Widget inside the Column Widget
Column(
children: [
Expanded(child: Container()),
Expanded(child: Center(child : Text("5"))), // or "6" or "7"
Expanded(child: Center(child : Text("No Slots"))) // or booking status
]
)
If you set crossAxisAlignment of the row to start and then show a column with "no slots" underneath, shouldn't this fix your issue?
You could use the CrossAxisAlignment.center:
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
),
Full snippet code:
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CustomText(
(dayModel?.date?.day ?? "").toString(),
AppTextStyle.Body,
customColor: _getColorBasedOnStyle(
dayModel.style,
),
),
Visibility(
visible: dayModel?.style == CalendarDayStyles.NOT_AVAILABLE,
child: CustomText(
Strings.no_slots_label,
AppTextStyle.SublineForCalendar,
customColor: AppColors.BLACK_20,
),
),
],
);

Is there a way to Stack a ListView on top of a Container, but is below it?

I'm trying to build an interface in Flutter.
I have a Container with Text (several lines depending on screen size) and a Button.
I also have a List of Widgets that have to be in front of the Container.
The first item of the list has to be below the Container. The List should be able tp scroll over the Container and the Container should fade away (but not move). The button should still be clickable.
I can't find a way to implement it.
Container
Widget container = Container(
child: Column(
children: <Widget>[
Container(child: Text("BlaBlabla ... long line"),
Container(child: Text("BlaBlabla ... another long line"),
Container(child: ButtonWidget(),
],
),
)
List
Widget list = ListView(
children: <Widget>[
CustomWidget(),
CustomWidget(),
CustomWidget(),
],
)
Put together: inside Scaffold Body
Stack(
children: <Widget>[
container,
Positioned(
#don't know height of the container
child: list,
),
],
)
or
Stack(
children: <Widget>[
container,
ListView(
children: <Widget>[
IgnorePointer( #can't click on the real container
child: Opacity(
child: container,
opacity: 0,
),
),
list #as column
],
),
],
)
or
Column(
children:<Widget>[
container,
list, #list can't scroll over the container because the ListView is not the whole body
],
)
edit: I added some of the combinations I thought could have been the solution, but unfortunately, none of them give worked for my intended purpose.
I appreciate any ideas that help.
It should look similar to the pictures below.