how to create stacked bar/progress bar in flutter like this image - flutter

I want to display
i dont know the name of this kind of visualization.
Right now,
I have 3 data here(sum, net, cancel)
The right side will display is cancel number, the left side display is net number inside the stacked bar
with this bar, user will immediately know the sum number by (net + cancel)
is there some kind of package that can help me to display this bar

Here is the widget builder that you want. Maybe the MediaQuery is a bad choice. But you can use any other sizing options.
Widget _buildProgress(BuildContext context, int progress, int limit) {
return SizedBox(
height: 30,
width: double.infinity,
child: Stack(
children: <Widget>[
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
color: Color(0xFF038918),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 20),
child: Text(
'$limit',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
Container(
width: MediaQuery.of(context).size.width / limit * progress,
decoration: const BoxDecoration(
color: Color(0xFFe40808),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
alignment: Alignment.center,
child: Text(
'$progress',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
}

Related

How to add images to the each steps in to anotherstepperbar on flutter?

I want to add steps images to each step in the "anotherstepper" bar how to do that?
code
Container(
width: 500,
height: 500,
child: AnotherStepper(
stepperList: stepperData,
stepperDirection: Axis.horizontal,
horizontalStepperHeight: 100,
dotWidget: Container(
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(30))),
child: Column(
children: <Widget>[
Row(children: const <Widget>[
Image(
image: AssetImage('assets/step1.png'),
height: 20,
width: 20,
),
]),
Row(children: const <Widget>[
Image(
image: AssetImage('assets/step2.png'),
height: 20,
width: 20,
),
]),
],
),
),
activeBarColor: Colors.green,
inActiveBarColor: Colors.grey,
activeIndex: 2,
barThickness: 8.5,
gap: 30,
),
),
Unfortunately, I can't upload images to StackOverflow .Then it says "Failed to upload image; an error occurred on the server".I hope you can understand what I mean by this question. Thank You!
Adding separate images/icons is not supported by the package version 1.0.4. But it will support changing icons for every stepper point in another_stepper: ^1.1.4.
Here is how you can implement this:
You get iconWidget inside the StepperData. You can add separate icons as follows:
List<StepperData> stepperData = [
StepperData(
title: "Order Placed",
subtitle: "Your order has been placed",
iconWidget: Container(
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(30))),
child: const Icon(Icons.looks_one, color: Colors.white),
)
),
StepperData(
title: "Preparing",
subtitle: "Your order is being prepared",
iconWidget: Container(
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(30))),
child: const Icon(Icons.looks_two, color: Colors.white),
)
),
StepperData(
title: "On the way",
subtitle: "Our delivery executive is on the way to deliver your item",
iconWidget: Container(
padding: const EdgeInsets.all(8),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(30))),
child: const Icon(Icons.looks_3, color: Colors.white),
)
),
StepperData(
title: "Delivered",
),
];
Now one point to note here is if you are sending icons of different height and width, you need to mention height and width in the Another Stepper widget
iconWidth: 40,
iconHeight: 40,

Container inside row flutter

i need to make a row inside of it i write the date in square then the tite of task and in the end of the row i added it a container in which i'm going to add the time .
but i get an error in the container
too many positional arguments: 0 expected, but 1 found.
can't we put a container inside the row ?
and as a design is it good ? how can i improve it i just need to show date task title and time
Widget build(BuildContext context) {
return Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20.0), //or 15.0
child: Container(
height: 60.0,
width: 60.0,
color: Color(0xffFF0E58),
child:
Center(
child: Text('27 juillet ' ,
style:TextStyle(
fontWeight: FontWeight.bold,
fontSize:16, )
,),
)
),
),
SizedBox(
width: 20.0,
),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Task tille',
style:TextStyle(
fontWeight: FontWeight.bold,
fontSize:16,
)
),
],
)
],
Container(
width: 40.0,
height: 20.0,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(30.0),
),
alignment: Alignment.center,
child: Text('8/34' , style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
) ,
No i just forget to close the ] of the row after the container that is the error
Okay, so your return type is Row(), that means, once the children: [Widgets here] is closed, you cannot add more widgets later. So my suggestion is to make the return type of 'Widget build' to Container() then add container's child as Column(), then use row within column's children.

How can i make flat button size as it's child size

i want to make button size like it's text child size
i will attach example photo , and i'll attach the code that i write
this is my code :
Expanded(
child: FlatButton(
minWidth: double.infinity,
height: 20,
child: FlatButton(
onPressed: (){},
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10) ,
),
child: Text(
'SHOP' ,
style: TextStyle(
color: Colors.blueAccent,
fontWeight: FontWeight.bold ,
fontSize: 16 ,
),
and this is the photo
photo
How about this?
RawMaterialButton(
constraints: BoxConstraints(),
padding: EdgeInsets.fromLTRB(14, 4, 14, 4),
elevation: 0,
onPressed: () {},
fillColor: Color(0xFFF2F2F2),
shape: StadiumBorder(),
child: Text(
'SHOP',
style: TextStyle(
color: Colors.blueAccent,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
Your question is confusing to me, I am not sure whether you want your button as big as the parent's child (as you stated in the title), or if you want it as big as the Text child (as you stated in the description of your question).
If what you want is the button to be as big as the parent, consider using LayoutBuilder and SizedBox to make the button as big as the available surrounding space. You can do something like this:
LayoutBuilder(
builder: (context, constraints) {
return SizedBox(
height: constraints.maxHeight,
width: constraints.maxWidth,
child: FlatButton(
...
)
)
}
)
If you want the button to be as big as its child, I believe you don't need to worry about anything other than providing the proper Text widget. FlatButton will figure out its size accordingly.
GestureDetector{
onTap:(){},
child:Container(
child:Material(
shape:RoundRectangleBorder()
child:Center(
child:'Text')))
}
You can use properties of Material widget this way. If you don't provide height to container it will adjust to the child size. i.e. text size
Try this for button function:
Expanded(
//Modify below factor as your requirement
flex: 1,
child: InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
//Modify width,height as your requirement
height: double.infinity,
width:double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.blueAccent.withAlpha(30),
),
child: Text('SHOP',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 20)),
),
)),

How to make this screen responsive in Flutter?

I'm kinda confused with how responsive layouts are made with flutter can you guys point me to the right direction or where in my codes will be wrapped in Expanded widget?
I tried wrapping the containers with Extended but It keeps showing an error and I'm getting confused now. I'm still a beginner, to be honest. Thank you very much!
Also, when I searched I found out that I should avoid using hardcoded sizes most of the time. So I want to learn when to apply Extended widget in order to make my screen responsive.
my code is below:
import 'package:flutter/material.dart';
class RegisterPage extends StatefulWidget {
RegisterPage({Key key}) : super(key: key);
#override
_RegisterPageState createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: Color(0xff0D192A),
body: Container(
child: ListView(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(10.0),
child: Container(
height: 200,
width: 200,
child: Image(
image: AssetImage("assets/images/vlogo.png"),
),
),
),
Padding(
padding: EdgeInsets.all(40.0),
child: Center(
child: Text("Register an Account",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20)),
)),
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text("Email Address",
style: TextStyle(
fontSize: 10.0, color: Colors.grey[400])),
],
),
],
),
),
SizedBox(height:10.0),
Container(
margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
padding: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter your email address",
hintStyle: TextStyle(color: Colors.grey[400]),
),
),
),
)
),
SizedBox(height:20.0),
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Text("Choose Password",
style: TextStyle(
fontSize: 10.0, color: Colors.grey[400])),
],
),
],
),
),
SizedBox(height:10.0),
Container(
margin: EdgeInsets.fromLTRB(20, 0, 20, 0),
padding: EdgeInsets.all(5.0),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter your email address",
hintStyle: TextStyle(color: Colors.grey[400]),
),
),
),
)
),
SizedBox(height: 50),
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: InkWell(
onTap: () {
setState(() {
});
},
child: Container(
height: 50,
decoration: BoxDecoration(
color: Color.fromRGBO(211, 184, 117, 100)
),
child: Center(
child: Text("Login", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 20),
),
),
),
),
),
],
),
],
),
),
),
);
}
}
Explore this plugin: This is one of the most effective plugins I have ever used for making responsive design.
https://pub.dev/packages/responsive_screen
Or
Use MediQuery() for getting the screen height and width i.e:-
Example:
#override
Widget build(BuildContext context) {
dynamic screenHeight = MediaQuery.of(context).size.height;
dynamic screenwidth = MediaQuery.of(context).size.width;
//use screenHeight and screenWidth variable for defining the height and
//width of the Widgets.
return Container(
height:screenHeight * .2, //It will take the 20% height of the screen
width: screenwidth * .5, //It will take the 50% width of the screen
//height: screenHeight, //It will take 100% height
child: Image(
image: AssetImage("assets/images/vlogo.png"),
);
}
You can make each screen responsive in flutter by just using MediaQuery or LayoutBuilder Concepts.
For your application, replace all your custom sizes like
width : MediaQuery.of(context).size.width * 0.1
height : MediaQuery.of(context).size.height * 0.3
MediaQuery gives you the sizes and orientation of the screen.
Even your padding, margin and other dimensions also should be calculated using MediaQuery to make it responsive.
Here, MediaQuery.of(context).size.width will give you the width of the current device screen and MediaQuery.of(context).size.height will give you the height of the current device screen.
Also, you can use LayoutBuilder Widget like,
LayoutBuilder(
builder: (context, constraints) {
if(constraints.maxWidth > 500) {
getLandscapeLayout();
} else {
getPortraitLayout();
}
},
)
LayoutBuilder is a widget which provides the dimensions of its parent so we can know how much space we have for the widget and can build it our child accordingly.
So these are two most powerful concepts are available in flutter to make your apps fully responsive.

How do I tweak my Flutter Stack widget to not have bottom overflowing?

[Update] : I got the solution, If you want the code, comment below or if you just want to know I've written it here :
The solution is to put the Cover Image and the Followers & Following inside a Column (as a single widget) and then put that Column and the Align (profile picture) both inside a Stack, then set the Fixed heightFactor.
So it would look something like this :
Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(), //The Cover Photo
Container(
child: Card() //The Followers and Following Card
)
]
),
Align() //The Profile Picture having fixed heightFactor
]
)
This solution is working on all 4 Devices I have + 2 Android Emulators (2 have 16:9 ratio, 2 have 18:9 and 2 have 19:9 ratio).
The problem is following :
On my device, which is having 18:9 Aspect Ratio there is no Bottom Overflowing issue.
But on devices having 16:9 Aspect Ratio it's having this issue.
This happens only when I try to set heightFactor of Followers & Following Align widget.
I tried to tweak many things in Stack so I could overcome this, but couldn't achieve similar result. So, I'm stuck with this.
Also, as far as I know I can overlap only by using Stack widget. If there is any possible option, do say.
Here is my code :
Stack(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 224.0,
margin: EdgeInsets.all(8.0),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(8.0),
image: DecorationImage(
image: NetworkImage("https://www.eta.co.uk/wp-content/uploads/2012/09/Cycling-by-water-resized-min.jpg"),
fit: BoxFit.cover
)
),
),
Align(
heightFactor: 5.0,
child: Container(
alignment: Alignment.bottomCenter,
width: MediaQuery.of(context).size.width,
height: 96.0,
margin: EdgeInsets.all(8.0),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
elevation: 0.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Followers",
style: TextStyle(
fontFamily: "Nunito",
fontWeight: FontWeight.bold,
color: Colors.blue
),
),
Text(
"3000",
style: TextStyle(
fontFamily: "Nunito",
color: Colors.blue
),
),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Following",
style: TextStyle(
fontFamily: "Nunito",
fontWeight: FontWeight.bold,
color: Colors.blue
),
),
Text(
"0",
style: TextStyle(
fontFamily: "Nunito",
color: Colors.blue
),
),
],
),
],
),
),
),
),
Align(
alignment: Alignment.bottomCenter,
heightFactor: 2.75,
child: Card(
color: Colors.transparent,
elevation: 0.0,
child: Container(
alignment: Alignment.bottomCenter,
width: 96.0,
height: 96.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage("https://cdn140.picsart.com/284302087007201.jpg?c256x256"),
fit: BoxFit.fill
),
border: Border.all(width: 4.0, color: Colors.blue)
),
),
),
),
],
),
You've provided the height of widget manually so it'll overflow on smaller screens. So you have to provide the height of widget depending upon the screen. You can use MediaQuery.of(context).size.height to get the height of the device.
And you can also multiply it with some number to get the height in percentage. For example, if you want 80% height of the screen then you can do MediaQuery.of(context).size.height * 80
The answer from #yashthakkar1173 is correct. That's one way of doing it. In addition to that I would say to his solution you can use
ConstrainedBox(
child: Card(),
constraints: BoxConstraints(
minHeight: 96.0,
maxHeight: 106.0,
))
What I observe is that you don't need the entire view to be in a Stack since it's just the top three widgets that overlap so I would wrap that stack in a column and set MainAxisSize to Min. I've done something similar, or you can set it to max so it'll always fill all the space left over.