I've provide the code. So the dragable widget is in the drawer and the drag target is in the home screen. But when I drag the container to put it in the drag target(home screen) the drawer doesn't close
If anyone have the full code that's working just like I discribe plz feel free to share cuz I think there's a lot of people trying to do this as well
`Drawer(
child: Column(children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Draggable(
child: Container(
color: Colors.red,
width: 250,
height: 100,
),
feedback: Container(
color: Colors.green,
width: 250,
height: 100,
),
childWhenDragging: Container(
color: Colors.grey,
width: 250,
height: 100,
),
),
),
]),
);
FloatingActionButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: const Icon(
Icons.add,
color: Colors.white,
size: 29,
),
backgroundColor: Colors.redAccent,
elevation: 0,
),`
when I create a drawer and put container and wrap with drag-able widget then I put a drag target inside the screen But when I try to drag it the drawer doesn’t close.So if you have any idea how to close the drawer when widget is drag plz answer down below
The Class Draggable provides a function called onDragStarted. If you place Navigator.pop in there it will close the drawer once the drag starts
Drawer(
child: Column(children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Draggable(
//This function should close the drawer
onDragStarted: () {
Navigator.pop(context);
},
child: Container(
color: Colors.red,
width: 250,
height: 100,
),
feedback: Container(
color: Colors.green,
width: 250,
height: 100,
),
childWhenDragging: Container(
color: Colors.grey,
width: 250,
height: 100,
),
),
),
]),
);
FloatingActionButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: const Icon(
cons.add,
color: Colors.white,
size: 29,
),
backgroundColor: Colors.redAccent,
elevation: 0,
),
Related
I have a Widget to creat a circular container. I want to place an icon on the buttom right, so I tried to use Positioned to place it where I want but its not moving. Its fixed on the center on the container.
Widget buildImage() {
return Center(
child: Container(
child: Material(
child: InkWell(
customBorder: CircleBorder(),
onTap: (){},
child: Container(
width: 150.0,
height: 150.0,
child: Positioned(
bottom: 4,
right: 0,
child: Icon (Icons.account_circle_rounded),
),
),
),
color: Colors.transparent,
),
decoration: BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
);
}
What am I doing wrong here?
Your answers are highly appreciated.
Positioned is used only in Stack widget. So if you want to position your icon inside Container, you can use Align widget, withPadding which will create desired behavior specified before in Positioned.
Somehow like this:
...
Container(
width: 150.0,
height: 150.0,
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 4.0),
child: Icon(
Icons.account_circle_rounded,
),
),
),
),
...
Container has align property you can use that or instead of Positined you can use Alignment Widget for Aligning your widget
For more control over postioning, just change the padding values.
Center(
child: Container(
child: Material(
child: InkWell(
customBorder: CircleBorder(),
onTap: () {},
child: Container(
width: 150.0,
height: 150.0,
child: Container(
padding: EdgeInsets.only(
right: 20, bottom: 10),
alignment: Alignment.bottomRight,
child: Icon(
Icons.account_circle_rounded),
),
),
),
color: Colors.transparent,
),
decoration: BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
),
I have a navigation menu which I created using a container, within my container there is a column which contains all my icons. When the user click's on certain icons or the login button at the bottom right corner I am suppose to be able to navigate/route to the next screen. I know that when we move to the next screen the menu on the left will disappear, is there a way to keep the menu bar persistent across all screens. I was assuming that I need to create a separate class/widget specifically for the menu bar and call it on each page that I route to. I am still new to flutter so I wasn't sure if there might be another approach to this problem. I also need to persist the row at the top onto all pages as well.
Widget build(BuildContext context) {
return Container(
width: 1280,
height: 800,
decoration: BoxDecoration(
color: Color.fromRGBO(227, 227, 227, 1),
),
child: Material(
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 80,
child: Container(
width: 1200,
height: 70,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Topbarbackground.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 652,
left: 0,
child: Container(
width: 1280,
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/Rectangle112.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 0,
left: 0,
child: Container(
child: ListView(
children: [
SizedBox(
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Back.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 150.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_load.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_eject.png'),
onPressed: () {
},
),
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Light.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Utility.png'),
onPressed: () {},
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Help.png'),
onPressed: () {},
),
),
SizedBox(
height: 100.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/User.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Power.png'),
onPressed: () {},
),
],
),
It is possible to do that. You have to put the sidebar in a separate widegt and then make a widget that shows it in a Row. Then you will need to change the builder of the main file in a way that the widget with the row can be displayed. This isn't the best explanation so I recommend you to read through this article:
https://medium.com/geekculture/persistent-widget-across-all-screens-using-flutter-navigator-45e6b2e57cf7
It showcases everything and gives you a short tutorial. I hope this helped.
When the sized box tapped, the ripple effect should happen on top of the widget. But it does not appear. The sized box appears, but ripple effect is not.
Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
width: widget.width,
height: widget.height,
child: Material(color: Colors.yellow, child: widget.icon
),
),
SizedBox(
width: widget.width,
height: widget.height,
child: InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
onTap: () {}),
),
],
),
]);
EDIT: Wrapped the whole stack with the inkwell but still ripple does not appear.
InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
width: widget.width,
height: widget.height,
child: Material(color: Colors.yellow, child: widget.icon
),
Add InkWell above icon that will give a ripple effect
Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
height: 48,
width: 48,
child: Material(
color: Colors.yellow,
child: InkWell(
splashColor: Colors.purple,
onTap: () {},
child: const Icon(Icons.add),
),
),
),
],
),
OR
Material(
color: Colors.yellow,
child: InkWell(
splashColor: Colors.purple,
onTap: () {},
child: Container(
color: Colors.transparent,
height: 80,
width: 80,
child: Icon(Icons.add),
),
),
),
Output:
You must put the sized box as child of inkwell (or even move the complete stack into the inkwell child).
Inkwell is applied to its children.
InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
onTap: () {
print('HEY');
},
child: SizedBox(
width: widget.width,
height: widget.height,
),
),
add onTap(){} to the inkWell, even if its not used. I think this fixes it, haven't tried it out tho. Also try wrapping the InkWell with a Material widget.
I would like to change the size of the button, by reducing the vertical size so it is a bit squished.
The current code that I have written is this:
Padding(
padding: const EdgeInsets.all(8),
child: Material(
color: Color(0xFF3E4685),
borderRadius: BorderRadius.circular(20),
elevation: 6,
child: MaterialButton(
height: 0,
onPressed: () {},
padding: EdgeInsets.symmetric(vertical: 0),
child: Icon(
Icons.arrow_right_alt_sharp,
size: 50,
color: Colors.white,
),
),
),
)
And the output is this:
Button
I would like for it to be a bit more squished so less vertical height, I have tried using the height property but it isn't working.
Try this one
SizedBox(
width: 150,
height: 150,
child: Material(
color: Color(0xFF3E4685),
borderRadius: BorderRadius.circular(20),
elevation: 6,
child: MaterialButton(
height: 0,
onPressed: () {},
padding: EdgeInsets.symmetric(vertical: 0),
child: Icon(
Icons.arrow_right_alt_sharp,
size: 50,
color: Colors.white,
),
),
),
or you can use ButtonTheme
ButtonTheme(
minWidth: 200.0,
height: 100.0,
child: YourButton
),
I have the following Flutter widget:
return SizedBox(
height: 40.0,
width: 40.0,
child: InkWell(
splashColor: Colors.grey,
onTap: callback,
child: Center(child: image),
),
);
The problem is that the highlight on this button is rectangular. I would like to change it to a circle, but the highlightShape property is not available for modification. How can this button be given a circular highlight?
Following #pskink's comment, I used customBorder:
return SizedBox(
height: 40.0,
width: 40.0,
child: InkWell(
splashColor: Colors.grey,
onTap: callback,
child: Center(child: image),
customBorder: CircleBorder(),
),
);
return ClipOval(
child: Material(
color: Colors.blue, // button color
child: InkWell(
splashColor: Colors.red, // inkwell color
child: SizedBox(width: 56, height: 56, child: Icon(Icons.settings)),
onTap: () {},
),
),
);
You can use ClipOval to achieve this
ClipOval(
child: Material(
child: SizedBox(
height: 40.0,
width: 40.0,
child: InkWell(
splashColor: Colors.grey,
onTap: () {},
child: Center(child: Icon(Icons.directions_car)),
),
),
),
)