How to use Stack and Positioned in Column - flutter

Need to adjust the position of the Flatbutton and IconButton in Raw. How to use Stack and Positioned in the below code. is it possible to apply stack and positioned in this code?
return MaterialApp(
home: Scaffold(
body: Column(children: [
FlatButton( // `need to position in bottom right side`
color: Colors.green,
textColor: Colors.black,
padding: EdgeInsets.all(8.0),
onPressed: () {},
child: Text(
'Save',
style: TextStyle(fontSize: 20.0),
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: GestureDetector(
child: IconButton( // `need to position in center`
icon: Icon(Icons.mic),
color: Colors.black,
iconSize: 50,
onPressed: () async {
startRecord();
}),
),
),
Expanded(
child: GestureDetector(
child: IconButton( // `need to position in bottom center'
icon: Icon(Icons.pause),
color: Colors.black,
iconSize: 50,
onPressed: () {
pauseRecord();
},
),
),
),
RecordMp3.instance.status == RecordStatus.PAUSE
? Expanded(
child: GestureDetector(
child: IconButton(
icon: Icon(Icons.play_arrow),
color: Colors.black,
iconSize: 50,
onPressed: () {
resumeRecord();
},
),
),
)
: SizedBox(),
Expanded(
child: GestureDetector(
child: IconButton(
icon: Icon(Icons.stop),
color: Colors.black,
iconSize: 50,
onPressed: () {
stopRecord();
},
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
statusText,
style: TextStyle(color: Colors.red, fontSize: 20),
),
),
isComplete && recordFilePath != null
? Expanded(
child: GestureDetector(
child: IconButton( // `need to position in between bottom and middle`
icon: Icon(Icons.play_circle_filled),
color: Colors.black,
iconSize: 50,
onPressed: () {
play();
}),
),
)
: SizedBox(),
]),
),
);
need to position the Flatbutton in the right bottom. need to position the Iconbuttons in middle and space between the middle and bottom.

Related

Container widget overflows other widgets- Flutter

This is the expected screen and the container will collapse and expand based on the text displayed and should only occupy the space left out by placing other icons.
But see the flutter implemented screen.
The icons are moved to the right on container expansion and shows overflowed pixel error.
My code
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(
Icons.menu,
color: Colors.black,
size: 34,
),
onPressed: () {},
),
//container section
GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius: BorderRadius.circular(40.0)),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Row(children: const <Widget>[
Text(
"Content is here",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black54,
fontSize: 19.0,
fontWeight: FontWeight.bold),
),
Icon(
Icons.arrow_drop_down,
color: Colors.black,
),
]),
),
),
),
onTap: () {
//todo show bottom sheet dialog here.
},
),
const Spacer(), // I just added one line
IconButton(
icon: Image.asset('assets/images/ic_scan.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_notification.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_search.png'),
iconSize: 20,
onPressed: () {},
),
],
),
);
Remove the spacer and add the dropdown in a flexible widget
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: const Icon(
Icons.menu,
color: Colors.black,
size: 34,
),
onPressed: () {},
),
Flexible(//<-------Flexible
child: GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 10, right: 10),
decoration: BoxDecoration(
color: Colors.red.shade100,
borderRadius: BorderRadius.circular(40.0)),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Align(
alignment: Alignment.centerLeft,
child: Row(
children: const <Widget>[
Flexible(//<-------Flexible
child: Text(
"Content is here",
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black54,
fontSize: 19.0,
fontWeight: FontWeight.bold),
),
),
Icon(
Icons.arrow_drop_down,
color: Colors.black,
),
]),
),
),
),
onTap: () {
//todo show bottom sheet dialog here.
},
),
),
//Spacer() //<--------remove this
IconButton(
icon: Image.asset('assets/images/ic_scan.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_notification.png'),
iconSize: 20,
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/ic_search.png'),
iconSize: 20,
onPressed: () {},
),
],
),
);

Change Footer Color in Flutter. (persistentFooterButtons)

I have a persistentFooterButtons option for my Scaffold.
persistentFooterButtons: [
FloatingActionButton(
heroTag: "editself",
child: Icon(Icons.edit),
onPressed: () {
print(InterfaceViewRoute);
Navigator.pushNamed(context, InterfaceViewRoute, arguments: "-1");
}),
FloatingActionButton(
heroTag: "scanneredit",
child: Icon(Icons.qr_code_scanner_rounded),
onPressed: () => _scan(),
),
],
);
But now the whole background is filled there. See image:
Is there a way to make this background transparent so that you can see the list all the way down
Transparent Footer with Floating Action buttons
This is a Code Snippet.
floatingActionButton: Container(
width: MediaQuery.of(context).size.width,
padding: const EdgeInsets.only(
left: 40.0,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
FloatingActionButton(
tooltip: 'Home',
child: Icon(
Icons.home,
color: Colors.black,
),
onPressed: () {},
backgroundColor: Colors.white.withOpacity(.4),
),
Spacer(),
FloatingActionButton(
tooltip: 'Details',
child: Icon(
Icons.details,
color: Colors.black,
),
onPressed: () {},
backgroundColor: Colors.white.withOpacity(.4),
),
Spacer(),
FloatingActionButton(
tooltip: 'Bar Chart',
child: Icon(
Icons.bar_chart_outlined,
color: Colors.black,
),
onPressed: () {},
backgroundColor: Colors.white.withOpacity(.4),
),
Spacer(),
FloatingActionButton(
tooltip: 'Settings',
child: Icon(
Icons.settings,
color: Colors.black,
),
onPressed: () {},
backgroundColor: Colors.white.withOpacity(.4),
),
],
),
),
Have you tried put Row in floatingActionButton?
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
),
SizedBox(width: 10,),
FloatingActionButton(
),
],
)),
Another way is to use bottomNavigationBar of Scaffold
...
extendBody: true, // if you want body to be extended below buttons
bottomNavigationBar: SafeArea(
child: Container(
child: TextButton(child: Text('button'), onPressed: () {}), //or row of buttons
width: MediaQuery.of(context).size.width,
color: Colors.transparent, //background color
padding: EdgeInsets.only(top: 5, bottom: 3),
),
),
...

How to prevent _persistentFooterButtons_ to get covered from activated keyboard?

When the keyboard is activated, persistentFooterButtons are covered.
...
persistentFooterButtons: <Widget>[
ButtonBar(
children: [
IconButton(
iconSize: 15,
onPressed: () {},
icon: Icon(Icons.east, color: Colors.green),
),
IconButton(
iconSize: 15,
onPressed: () {},
icon: Icon(Icons.api, color: Colors.blue),
),],),],
); //Scaffold
When the keyboard is activated, the icons should be displayed above the keyboard.
write in floatingActionButton
for example :
floatingActionButton: Column(
children: [
Row(
children: [
Expanded(child: Container()),
FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
],
),
Container(
height: 1, color: Colors.grey , margin: EdgeInsets.only(top: 10 , left: 30),
),
Container(
child: ButtonBar(
children: [
IconButton(
iconSize: 15,
onPressed: () {},
icon: Icon(Icons.extension, color: Colors.green),
),
IconButton(
iconSize: 15,
onPressed: () {},
icon: Icon(Icons.ac_unit, color: Colors.blue),
),
],
),
)
],
mainAxisAlignment: MainAxisAlignment.end,
), //

Remove extra space between two IconButton in ROw

I want to remove some extra space between two IconButton in Row widget
I tried much more but still not able to remove space between widgets
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Home",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Colors.black
)
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
icon: Icon(
Icons.edit,
color: Colors.black,
size: 20,
),
onPressed: () {
IntelUtility.navigateToScreen(
context, EditHomeAddressScreen()
);
},
),
IconButton(
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
),
],
),
],
),
],
),
Please help to solving this issue i am in trouble :(
Instead of using IconButton,
you can use CupertinoButton like this :
CupertinoButton(
minSize: double.minPositive,
padding: EdgeInsets.zero,
child: Icon(
Icons.delete,
color: Color.black,
size: 20
),
onPressed: () {},
)
Add param padding: EdgeInsets.all(0) to IconButton.
IconButton(
padding: EdgeInsets.all(0),
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
)
Your answer is BoxConstraints
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
constraints: BoxConstraints.tight(Size.fromWidth(30)),
icon: Icon(
Icons.edit,
color: Colors.black,
size: 20,
),
onPressed: () {
IntelUtility.navigateToScreen(
context, EditHomeAddressScreen()
);
},
),
IconButton(
constraints: BoxConstraints.tight(Size.fromWidth(30)),
icon: Icon(
Icons.delete,
color: Colors.black,
size: 20,
),
onPressed: () {},
),
],
),
You can change constraints: BoxConstraints.tight(Size.fromWidth(30)), whatever you want

How to code add button like zoom at in Flutter

I need to implement a button like a zoom at when we click on "+" the value should be incremented and when we click "-" the value should be decremented and the calculate value should be shown in the middle of "+" and "-" on the button.
RawMaterialButton(
fillColor: Colors.green,
splashColor: Colors.greenAccent,
onPressed: onPressed,
shape:const StadiumBorder(),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Row(
children: <Widget>[
const Icon(
Icons.add,
color: Colors.white,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("ADD",
style: TextStyle(
color: Colors.white,
),
),
),
const Icon(
Icons.remove,
color: Colors.white,
)
],
),
));
**but I don't know how to create two different buttons
I need just design part **
In a row, you can use IconData(-), Text(5) and IconData(+) like:
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Material(
child: IconButton(
icon: Icon(Icons.remove_circle_outline,
color: Colors.black),
onPressed: () {
_decrementValue(value);
}),
)),
Expanded(
child: Text(
'${value}',
textAlign: TextAlign.center,
)),
Expanded(
child: Material(
child: IconButton(
icon: Icon(Icons.add_circle_outline,
color: Colors.black),
onPressed: () {
_incrementValue(value);
}),
)),
],
),
)
And in _incrementValue() and _decrementValue() method, you can use your logic.