Make CircularPercentIndicator overflow into Text - flutter

I have a CircularPercentIndicator with a Text under it.
It looks like this
I want the CircularPercentIndicator to overlap into Area 1, how do I do this?
My code
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularPercentIndicator(
radius: 20.0,
lineWidth: 2.0,
percent: 0.10,
center: Text(
"10%",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
),
),
progressColor: Colors.red,
),
// Padding(
// padding:
// EdgeInsets.symmetric(horizontal: 10.0),
// child: Text("Area 1"),
// ),
Padding(
padding: EdgeInsets.only(),
child: Text(
"Area 1",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey[400],
backgroundColor: Colors.black),
),
)
],
),

using a Stack
Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 12),
child: Container(
//The Container here to fill the CircularPercentIndicator with color grey, tried using "fillColor" property and it filled it as a square
decoration: BoxDecoration(borderRadius: BorderRadius.circular(35),color: Colors.grey),
child: CircularPercentIndicator(
backgroundColor: Colors.black,
radius: 35.0,
lineWidth: 2.0,
percent: 0.10,
center: Text(
"10%",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
),
),
// progressColor: Colors.red,
),
),
),
Positioned(
bottom: 1,
child: Container(
color: Colors.black,
//Width is as twice as radious(Dia of the indicator) as in example image
width: 70,
height: 30,
child: Center(
child: Text(
"Area 1",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey[400],
),
),
),
),
),
],
),

Related

Stack item are not positioned when the screen size changes Flutter

1-I am making a simple app where I am creating Profile section Where there is Stack at the top with two widgets
but the problem is when ever I test the app on different screen sizes the Stack item widgets are not at same position even i tried with MediaQuery
2-And the Second issue is I want the Circle Avatar to be place Half inside the Container And Half Out-side the Container.
Here is my Profile.dart class
class SettingsScreen extends StatelessWidget {
const SettingsScreen({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
// height: mediaQueryData.size.height * 0.4,
height: 300,
width: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [
Colors.black,
Color.fromRGBO(255, 243, 18, 3),
], begin: Alignment.topLeft, end: Alignment.bottomRight),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50))),
),
const Padding(
padding: EdgeInsets.only(top: 240, left: 140),
child: CircleAvatar(
backgroundColor: Color.fromARGB(183, 40, 46, 3),
radius: 50,
child: Text(
"M-E",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 32),
),
),
),
Positioned(
top: 110,
left: 40,
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),
//),
],
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 0),
child: ListTile(
trailing: const Icon(
Icons.cast_for_education,
color: Colors.black,
),
title: const Text(
"Subjects (مضامین)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.contacts,
color: Colors.black,
),
title: const Text(
"Contact (رابطہ )",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.settings,
color: Colors.black,
),
title: const Text(
"Setting (ترتیبات)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
const Divider(
color: Colors.black,
thickness: 0.5,
),
Padding(
padding: const EdgeInsets.only(top: 2),
child: ListTile(
trailing: const Icon(
Icons.logout,
color: Colors.black,
),
title: const Text(
"Logout (لاگ آوٹ)",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 18),
),
onTap: () {},
),
),
],
),
],
),
));
}
}
Here is the const result I want when the app run on different devices
Here is the result I don't want to be happens whenever the device size changes
Use this structure.
Positioned(
top: 110,
left: 1,
right:1
child: Text(
"مثابة ايلاف",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 70),
),
),

Multiple Texts inside a container - how to add 'BTC' Text under the STORE OF VALUE section

// ignore_for_file: sort_child_properties_last, prefer_const_constructors, prefer_const_literals_to_create_immutables
import 'package:flutter/material.dart';
class StockPage extends StatelessWidget {
const StockPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.green,
elevation: 0,
title: Text(
'PiyaSync',
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
),
body: GridView(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
children: [
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'STORE OF VALUE',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
),
),
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'SMART CONTRACTS',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
)),
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'DEFI',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
),
),
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'MEMES',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
)),
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'CENTRALIZED EXCHANGE TOKENS',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
)),
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'NFTS',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
)),
],
),
);
}
}
/*ListView(
children: <Widget>[
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'STORE OF VALUE',
style: TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.w900),
),
Text(
'SOFTWARE - INFRASTRUCTURE',
style: TextStyle(
color: Colors.black,
fontSize: 13,
fontWeight: FontWeight.w900),
)
],
),
)
],
)*/
/*Column(
children: <Widget>[
Expanded(
child: ListView(
children: [
Text(
'STORE OF VALUE',
style: TextStyle(fontSize: 21, fontWeight: FontWeight.bold),
),
Expanded(
child: Container(
child: Text(
'BTC',
style:
TextStyle(fontSize: 25, fontWeight: FontWeight.w500),
),
color: Colors.green,
padding: EdgeInsets.only(left: 1),
margin: EdgeInsets.all(1),
),
),
],
),
),
],
),*/
/* Container(
width: 210, //360
height: 100, //230
color: Colors.green,
child: Align(
alignment: Alignment.center,
child: Text(
'ETH',
style: TextStyle(
height: -1,
fontWeight: FontWeight.w500,
fontSize: 25,
),
),
),
),*/
/*Padding(
padding: const EdgeInsets.only(right: 260),
child: Container(
height: 265,
color: Colors.white,
alignment: Alignment.topLeft,
child: Column(children: [
Text(
"STORE OF VALUE",
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
),
),
Container(
width: 210, //360
height: 130, //230
color: Colors.green,
child: Align(
alignment: Alignment.center,
child: Text(
'BTC',
style: TextStyle(
height: -1,
fontWeight: FontWeight.w500,
fontSize: 25,
),
),
),
),
Stack(
children: [
Positioned(
left: 20,
top: 20,
child: Container(
height: 200,
width: 200,
color: Colors.black,
child: Text('ETH'),
),
),
],
)
]),
),
),*/
You can use \n for new line and btc will be diaplayed below the other text
Container(
color: Colors.green,
margin: EdgeInsets.all(10),
child: Text(
'STORE OF VALUE\nBTC',
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w500),
),
),

Move elements in ConstrainedBox

I have a code that is responsible for displaying the characteristics of the device.
I put these characteristics in Column, wrapped Card, and listed everything.
I am attaching a short code example.
Container(
constraints: const BoxConstraints(maxWidth: 800),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(5.0),
border: Border.all(
color: Colors.black,
width: 2,
),
),
child: Card(
child: Column(
children: [
Text(
'Location:',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(
device.location,
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
const Divider(
color: Colors.black, endIndent: 10, indent: 10),
Text(
'Status:',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 250),
child: Padding(
padding:
const EdgeInsets.fromLTRB(30, 0, 0, 0),
child: Row(children: [
Expanded(
child: Text(
device.status.toString().substring(7),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
),
),
Expanded(
child: (device.status == Status.booked)
? OutlinedButton(
onPressed: () async {
final user = await user_api
.getUser(device.userId);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const UserCard(),
settings: RouteSettings(
arguments:
user, //TODO: check route
),
),
);
},
child: const Text("User",
style: TextStyle(
fontSize: 15,
color: Colors.black,
)),
style: OutlinedButton.styleFrom(
fixedSize: const Size(100, 15),
side: BorderSide(
width: 1.0,
color: Colors.black),
backgroundColor:
Colors.yellow[600],
),
)
: Text(''),
),
]))),
const Divider(
color: Colors.black, endIndent: 10, indent: 10),
],
),
),
),
const SizedBox(
height: 5,
),
Photo how it looks
But I would like to move the "User" button in the status column to the right. Tell me how can I do this?
The barrier is coming from BoxConstraints(maxWidth: 250). To handle view in row, we can use Row with mainAxisAlignment: MainAxisAlignment.spaceBetween, with Expanded 3 children for separation, also while using padding, provide save value on both side.
ConstrainedBox(
constraints:
const BoxConstraints(), //remove width, you can remove ConstrainedBox widget
child: Padding(
padding: const EdgeInsets.fromLTRB(
30, 0, 30, 0), // prvide same padding
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: SizedBox()), //handle left sepration
const Expanded(
child: Text(
"device",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
),
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: OutlinedButton(
onPressed: () async {},
child: const Text("User",
style: TextStyle(
fontSize: 15,
color: Colors.black,
)),
style: OutlinedButton.styleFrom(
fixedSize: const Size(100, 15),
side: BorderSide(
width: 1.0, color: Colors.black),
backgroundColor: Colors.yellow[600],
),
),
),
)
]))),

How to set icon to topRight

My widget inside row, and I want to set Icon widget possition on topRight but always fail beacuse my Icon always in center possition
I already use
Align(
alignment: Alignment.topRight,
child: Icon(
LineAwesomeIcons.heart,
color: lightColor,
size: 36,
),
)
To force possition but always fail. How to achieve this situation? Icon always be center
My layout
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(
vertical: 14.0,
horizontal: 18.0,
),
margin: EdgeInsets.only(
bottom: 20.0,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.0),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1.0,
blurRadius: 6.0,
),
],
),
child: Row(
children: <Widget>[
CircleAvatar(
backgroundColor: Color(0xFFD9D9D9),
backgroundImage: NetworkImage(USER_IMAGE),
radius: 36.0,
),
SizedBox(width: 10.0),
Flexible(
child: RichText(
text: TextSpan(
text: widget.status + "\n",
style: TextStyle(
color: Colors.purple,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1.3,
),
children: <TextSpan>[
TextSpan(
text: widget.name + "\n",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 1.3,
),
),
TextSpan(
text: widget.address,
style: TextStyle(
color: Colors.black38,
fontWeight: FontWeight.w400,
fontSize: 14,
),
),
],
),
),
),
SizedBox(width: 10.0),
Icon(
LineAwesomeIcons.heart,
color: lightColor,
size: 36,
)
Align(
alignment: Alignment.topRight,
child: Icon(
LineAwesomeIcons.heart,
color: lightColor,
size: 36,
),
)
],
),
);
}
I want to output like
Try this one
Container(
padding: EdgeInsets.symmetric(
vertical: 14.0,
horizontal: 18.0,
),
margin: EdgeInsets.only(
bottom: 20.0,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.0),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1.0,
blurRadius: 6.0,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
CircleAvatar(
backgroundColor: Color(0xFFD9D9D9),
backgroundImage: NetworkImage('https://banner2.cleanpng.com/20180920/yko/kisspng-computer-icons-portable-network-graphics-avatar-ic-5ba3c66df14d32.3051789815374598219884.jpg'),
radius: 36.0,
),
SizedBox(width: 10.0),
Flexible(
child: RichText(
text: TextSpan(
text: "status\n",
style: TextStyle(
color: Colors.purple,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1.3,
),
children: <TextSpan>[
TextSpan(
text: "Name \n",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w600,
height: 1.3,
),
),
TextSpan(
text: 'Poplar pharma limited Dermatologist San Franscisco CA|5',
style: TextStyle(
color: Colors.black38,
fontWeight: FontWeight.w400,
fontSize: 14,
),
),
],
),
),
),
SizedBox(width: 10.0),
],
),
),
Align(
alignment: Alignment.topCenter,
child: Icon(
Icons.help,
color: Colors.cyan,
size: 36,
),
),
],
),
)
Set crossAxisAlignment to CrossAxisAlignment.start in your Row
Like this
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children : [...]
)
UPDATE
The avatar stays in the center
Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(),
SizedBox(width: 20),
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("fhfhfj\nufhfhjfhf\njifjifjifj\n",
style: TextStyle(color: Colors.black)),
SizedBox(width: 20),
Icon(Icons.favorite, color: Colors.black),
],
),
],
)

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