I'm new to flutter and I recently encountered a small problem I haven't been able to solve. I tried recreating the flutter default app using a stateful widget, I defined the body()
of the app in the stateful widget and returned a Center()
. The problem now is that the FloatingActionButton()
is centered too.
I've tried
Using wrapping it in a Padding()
but I can only change the values for the left and right values without distorting the UI of the app The Output My Code
CodePudding user response:
Use the Scaffold
s floatingActionButton
property instead of embedding it inside the body
of the Scaffold
Scaffold(
body: Center(
child: MyWidget(),
),
floatingActionButton: FloatingActionButton(),
),
CodePudding user response:
This is because you have placed a floating action button in your body part. That's why when you centered the widget a Floating Action button is centered Too. You can use the default property of Scaffold for your app.
Scaffold(
body: Center(
child: Text("Hello Flutter"),
),
floatingActionButton: FloatingActionButton(child: Icon(Icons.plus)),
),
This will solve your Issue.