how to set fix size of gridiew on random text - flutter

child: Card(
elevation: 10,
child: Container(
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(7)),
height: 50,
width: 50,
margin: EdgeInsets.all(5),
child: Center(
child: Text(
"${toplist[index]}".toUpperCase(),
style: TextStyle(
fontSize: 20,
fontFamily: "regular",
color: Colors.white,
fontWeight: FontWeight.bold),
)),
),
),
every time change value of the text in gridview and change the container size, I get a fixed size of the container on every random text.

Put your (Card) Widget inside a (FittedBox) Widget, and select (scaleDown) to your (fit option) as you see below in the code sample.
FittedBox(
fit: BoxFit.scaleDown,
child: Card(
elevation: 10,
child: Container(
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(7)),
height: 50,
width: 50,
margin: EdgeInsets.all(5),
child: Center(
child: Text(
"${toplist[index]}".toUpperCase(),
style: TextStyle(
fontSize: 20,
fontFamily: "regular",
color: Colors.white,
fontWeight: FontWeight.bold),
)),
),
),
),

Related

Flutter row alignment

i would like to have the title exactly in the center of the screen and not the same distance between the other two row children.
Currently I have a row with mainAxisAlignment set to spaceBetween but this is not what I am looking for.
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 35,
height: 35,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(image: NetworkImage("...")),
color: Colors.white),
),
const Text(
"TITLE",
style: TextStyle(
fontFamily: "IBM",
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.black,
),
),
Timer(),
],
If you like to have appBar, use centerTitle: true, on appBar.
appBar: AppBar(
title: Text("C"),
centerTitle: true,
leading: Container(
width: 35,
height: 35,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(image: NetworkImage("...")),
color: Color.fromARGB(255, 24, 11, 11)),
),
actions: [
CircleAvatar(
backgroundColor: Colors.red,
),
],
),
While the height is fixed, you can use Stack widget.
SizedBox(
width: MediaQuery.of(context).size.width,
height: 35,
child: Stack(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
width: 35,
height: 35,
decoration: const BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(image: NetworkImage("...")),
color: Color.fromARGB(255, 24, 11, 11)),
),
),
Align(
alignment: Alignment.center,
child: const Text(
"TITLE",
style: TextStyle(
fontFamily: "IBM",
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.black,
),
),
),
Align(
alignment: Alignment.centerRight,
child: CircleAvatar(
backgroundColor: Colors.red,
),
)
],
),
),
You can also use Positioned widget to align the items.
To have TITLE centered in this case you should make the right and left Widget having the same width. You can wrap them in a SizedBox

How to set a image inside a container but also expand outside the container in flutter

I tried to code this all the way I can, but It's still can't move .
I tried to wrap this all in stack and I put the picture as second child, even if i adjust the container width, the image can't get out of the card, and the card padding is stuck there, I can't change anything, how do i fix that
here is the example design
here is my code
children: [
SizedBox(height: 37),
const Text("Hey Mishal,",
style: TextStyle(
fontSize: 26,
color: Color(0xFF0D1333),
fontWeight: FontWeight.bold,
)),
const Text("Find a course you want to learn",
style: TextStyle(
fontSize: 20,
color: Color(0xFF61688B),
height: 2,
)),
Container(
height: 150,
width: 357,
alignment: Alignment.topLeft,
margin: const EdgeInsets.symmetric(vertical: 30),
decoration: BoxDecoration(
color: kDeepBlueTheme,
borderRadius: BorderRadius.circular(15)),
child: Stack(
children: [
Card(
color: Colors.blueAccent,
child: Padding(
padding: const EdgeInsets.only(left: 15, top: 23),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// SizedBox(height: 30, width: 100,),
const Text('50% off',
style: TextStyle(
color: Colors.white,
fontSize: 27,
fontWeight: FontWeight.bold)),
const SizedBox(
height: 5,
),
const Text('For Any Courses',
style: TextStyle(
letterSpacing: 2,
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w300)),
const SizedBox(
height: 6,
),
ElevatedButton(
//on pressed
onPressed: () async {},
//text to shoe in to the button
child: const Text('Join Now!',
style: TextStyle(color: kMainTheme)),
//style section code here
style: ButtonStyle(
elevation:
MaterialStateProperty.all<double>(0),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
backgroundColor:
MaterialStateProperty.all<Color>(
Colors.black),
),
),
]),
),
),
Positioned(
bottom: 1,
left: 100,
child: Image.asset(
'assets/person_home.png',
height: 230,
),
)
],
),
),
],
and here is my result ,
how can I achieve that ?
Wrap your Stack with a SizedBox and give it a height greater than the height of Card, use media query heights to make it responsive.
SizedBox(
height: 220,
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
height: 200,
width: double.infinity,
padding: const EdgeInsets.all(8.0),
child: Card(
color: Colors.blueAccent,
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('50% off',
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold)),
const SizedBox(
height: 5,
),
const Text('For Any Courses',
style: TextStyle(
letterSpacing: 2,
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w300)),
const SizedBox(
height: 6,
),
ElevatedButton(
//on pressed
onPressed: () async {},
//text to shoe in to the button
child: const Text('Join Now!',
style: TextStyle(color: Colors.white)),
//style section code here
style: ButtonStyle(
elevation: MaterialStateProperty.all<double>(0),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
backgroundColor:
MaterialStateProperty.all<Color>(Colors.black),
),
),
]),
),
),
),
Positioned(
right: 0,
top: 0,
child: Image.network(
'https://i.ibb.co/7Kr3Vc2/Screenshot-2022-02-23-at-6-11-05-PM-removebg-preview.png',
fit: BoxFit.cover,
height: 210,
),
)
],
),
),
Try This Result Will be like in pic..
Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 400,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.blueGrey,
),
),
),
Row(
children: [
const Padding(
padding:EdgeInsets.only(left: 20,right: 5),
child: Text('hello'),
),
Spacer(),
SizedBox(
height: 700,
child: Image.asset('assets/images/place_holder_avatar.png',fit: BoxFit.cover,),
),
],
),
],
)

How to make text align to centre of a Sizedbox in Flutter

i use text inside a sizedbox in flutter and the text is sticked to the top of the box how can i put the text in the middle of the box.
child: Container(
width: 240.0,
height: 42.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: const Color(0xff2c2c2c),
),
child: SizedBox(
child: Text(
'SIGN UP',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
color: Colors.white,
height: 1,
),
textAlign: TextAlign.center,
),
),
),
Wrap the Text in a Center widget
child: Container(
width: 240.0,
height: 42.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: const Color(0xff2c2c2c),
),
child: Center(
child: Text(
'SIGN UP',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
color: Colors.white,
height: 1,
),
textAlign: TextAlign.center,
),
),
),
Also, as far I can tell, you can remove the SizedBox widget, This is the result

How to add an Icon left of text inside container

I have the following below widget:
Widget get _animatedButtonUI => Container(
height: 60,
width: 290,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF9EC33B),
),
borderRadius: BorderRadius.circular(100.0),
color: Colors.white,
),
child: Center(
child: Text(
'COTINUE WITH GOOGLE',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
color: Color(0xFF9EC33B),
),
),
),
);
as it was looks like the below figure:
Now I need to add Icon left of the Text as the below image:
So how can I do this....
You just have to insert a Row inside the Container, just like this:
Container(
height: 60,
width: 290,
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF9EC33B),
),
borderRadius: BorderRadius.circular(100.0),
color: Colors.white,
),
child: Row(
children: <Widget>[
Image.asset(yourImage),
Center(
child: Text(
'COTINUE WITH GOOGLE',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
color: Color(0xFF9EC33B),
),
),
),
],
);
Edit: Make sure you fix that typo ("COTINUE WITH GOOGLE" => "CONTINUE WITH GOOGLE")

How to make cards swipeable like tabs in flutter? [duplicate]

This question already has answers here:
Horizontally scrollable cards with Snap effect in flutter
(6 answers)
Closed 3 years ago.
I have been trying to make cards swipeable like tabs as shown in my mocks.
I have added my code and mock for reference.
Code:
Container(
margin: EdgeInsets.only(top: 35),
child: Center(
child: Card(
child: InkWell(
// splashColor: Colors.blue.withAlpha(30),
onTap: () {
print('Card tapped.');
},
child: Container(
width: 300,
height: 450,
padding: EdgeInsets.all(30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'3 month Test Pass',
style: TextStyle(
fontSize: 23, fontWeight: FontWeight.bold),
),
Container(
margin: EdgeInsets.only(top: 10),
child: Text(
'50% off for early Birds',
style: TextStyle(
color: Colors.black54, fontSize: 16),
),
),
Container(
margin: EdgeInsets.only(top: 40),
child: Text(
'INR 49/month',
style: TextStyle(
fontSize: 21, fontWeight: FontWeight.bold),
),
),
Container(
margin: EdgeInsets.only(top: 7),
child: Text(
'INR 147 for 90 days',
style: TextStyle(
color: Colors.black54,
fontSize: 16,
fontWeight: FontWeight.bold),
),
),
Container(
margin: EdgeInsets.only(top: 30),
child: Text(
'New live exam every Monday',
style: TextStyle(
color: Colors.black87,
fontSize: 16,
),
),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text(
'Unlimited practise tests series',
style: TextStyle(
color: Colors.black87,
fontSize: 16,
),
),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text(
'Paper tailored by AI for you',
style: TextStyle(
color: Colors.black87,
fontSize: 16,
),
),
),
Container(
margin: EdgeInsets.only(top: 15),
child: Text(
'Solved previous year questions',
style: TextStyle(
color: Colors.black87,
fontSize: 16,
),
),
),
Container(
margin: EdgeInsets.only(top: 35),
child: RaisedButton(
padding: const EdgeInsets.only(top:10,bottom:10,left:40,right: 40),
textColor: Colors.black,
color: Colors.green,
child: Text('Buy Now',style: TextStyle(fontSize: 20),),
onPressed: null,
),
),
],
),
),
),
),
),
)
This is a container showing only one card, which is added in an array of Column in the body of Scaffold.
The idea is to have horizontally swipeable cards to make the user see the plans.
I am a beginner in Flutter.
You can use a ListView then set the scroll direction to horizontal
Just put all your containers / cards in the list view
Example:
ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
],
),
References
ListView - horizontal