How can I perfectly align a column above another - flutter

I have this widget with a slider and a ruler:
how can I make the start and the end of the ruler align itself with the beginning and end of the slider?
Here is my code, I tried to put the slider inside a column and a row after it.
The expected result would be something like this:
Also, I am trying to mimic the ruler scale with a short width container and putting it inside a column to center aling the text with the scale.
class RulerWidget extends StatefulWidget {
const RulerWidget({super.key});
#override
State<RulerWidget> createState() => _RulerWidgetState();
}
class _RulerWidgetState extends State<RulerWidget> {
double _width = 0;
double _value = 1;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Column(
children: [
Align(
child: SizedBox(
width: _width + 48,
child: Slider(
thumbColor: primaryColor,
activeColor: primaryColor,
min: 1,
max: 9,
divisions: 8,
label: '${_value.round()}km',
value: _value,
onChanged: (value) {
setState(() {
_value = value;
});
},
),
),
),
MeasuredSize(
onChange: (size) => setState(() => _width = size.width),
child: SizedBox(
width: 300,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'1km',
style: TextStyle(color: mediumGrey, fontSize: 10),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'2km',
style: TextStyle(
color: Colors.transparent,
fontSize: 10,
),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'3km',
style: TextStyle(color: mediumGrey, fontSize: 10),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'4km',
style: TextStyle(
color: Colors.transparent,
fontSize: 10,
),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'5km',
style: TextStyle(color: mediumGrey, fontSize: 10),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'1km',
style: TextStyle(
color: Colors.transparent,
fontSize: 10,
),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'7km',
style: TextStyle(color: mediumGrey, fontSize: 10),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'1km',
style: TextStyle(
color: Colors.transparent,
fontSize: 10,
),
),
],
),
Column(
children: [
Container(
color: mediumGrey.withOpacity(0.6),
width: 2,
height: 7,
),
const SizedBox(height: 4),
const Text(
'9km',
style: TextStyle(color: mediumGrey, fontSize: 10),
),
],
),
],
),
),
),
],
),
);
}
}

I don't have a direct answer to your question, but I can recommend you a grate package for UI Elements like that.
Syncfusion

Instead of the Column, use Stack to wrap the slider and measured-size widgets to overlap them.
To meet your requirements, you may need to wrap the measured-size widget with Positioned widget
Stack(
children: [
Slider(),
MeasuredSize(),
]
)

Related

Flutter comment_tree 0.3.0 How to remove replies under comments

I use the component as in the description, I can’t figure out how to remove the answer (child component) in the component itself, or at least how to check if it exists, then show it, if not, then don’t show it.
https://gist.github.com/lomanu4/3abba49f6fbcecbde4c07df82c3ce11c
class _ComentCardState extends State<ComentCard> {
bool childcomment = false;
#override
Widget build(BuildContext context) {
return Column(children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
child: CommentTreeWidget<Comment, Comment?>(
Comment(
avatar: 'null',
userName: widget.snap['name'],
content: '${widget.snap['text']} '),
[
Comment(avatar: 'null', userName: 'null', content: 'null'),
],
treeThemeData: childcomment
? TreeThemeData(lineColor: Colors.green[500]!, lineWidth: 3)
: TreeThemeData(lineColor: Colors.green[500]!, lineWidth: 3),
avatarRoot: (context, data) => PreferredSize(
preferredSize: const Size.fromRadius(18),
child: Row(
children: [
CircleAvatar(
radius: 18,
backgroundColor: Colors.grey,
backgroundImage:
NetworkImage(widget.snap['profilePic'].toString()),
),
],
),
),
avatarChild: (context, data) => const PreferredSize(
preferredSize: Size.fromRadius(12),
child: CircleAvatar(
radius: 12,
backgroundColor: Colors.grey,
backgroundImage: AssetImage('lib/assets/homescreen.png'),
),
),
contentChild: (context, data) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(12)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'dangngocduc',
style: Theme.of(context).textTheme.caption?.copyWith(
fontWeight: FontWeight.w600, color: Colors.black),
),
const SizedBox(
height: 4,
),
Text(
'${data!.content}',
style: Theme.of(context).textTheme.caption?.copyWith(
fontWeight: FontWeight.w300, color: Colors.black),
),
],
),
),
DefaultTextStyle(
style: Theme.of(context).textTheme.caption!.copyWith(
color: Colors.grey[700], fontWeight: FontWeight.bold),
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: const [
SizedBox(
width: 8,
),
Text('Reply'),
],
),
),
)
],
);
},
contentRoot: (context, data) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(12)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.snap['name'],
style: Theme.of(context).textTheme.caption!.copyWith(
fontWeight: FontWeight.w600, color: Colors.black),
),
const SizedBox(
height: 4,
),
Text(
'${data.content}',
style: Theme.of(context).textTheme.caption!.copyWith(
fontWeight: FontWeight.w300, color: Colors.black),
),
const SizedBox(
height: 4,
),
],
),
),
DefaultTextStyle(
style: Theme.of(context).textTheme.caption!.copyWith(
color: Colors.grey[700], fontWeight: FontWeight.bold),
child: Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: [
SizedBox(
width: 8,
),
Text('Like'),
SizedBox(
width: 24,
),
Expanded(child: Text('Reply')),
Container(
padding: const EdgeInsets.all(8),
child: const Icon(
Icons.favorite_border,
size: 16,
),
)
],
),
),
),
],
);
},
),
),
]);
}

Google Map behaving Weird in Scrollable Widget (inside ListView.builder)

I need to show Google Map in ListView.builder. in Ios its behaving weird. the App Header and Bottom App Bar got scrolled with White Space. GoogleMap get freeze as well.
SingleChildScrollView(
child: Container(
margin: EdgeInsets.all(10.0),
child: ListView.separated(
itemCount: state.products.length,
separatorBuilder:
(BuildContext context, int index) => SizedBox(
height: 10,
),
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, position) {
return PharmaciesItemWidget(
pharmacies: state.products[position],
remove: true,
removeBottom: true,
onTap: () {
BlocProvider.of<PharmaciesCubit>(context)
.deletePharmacy(
state.products[position].uuid);
},
);
// return Text("$position");
},
),
),
)
/// List Item Class
class PharmaciesItemWidget extends StatefulWidget {
final PharmaciesData pharmacies;
final VoidCallback onTap;
final bool remove;
final bool removeBottom;
const PharmaciesItemWidget({
Key key,
#required this.pharmacies,
this.onTap,
this.remove = false,
this.removeBottom = false,
}) : super(key: key);
#override
_PharmaciesItemWidgetWidgetState createState() =>
_PharmaciesItemWidgetWidgetState();
}
class _PharmaciesItemWidgetWidgetState extends State<PharmaciesItemWidget> {
#override
Widget build(BuildContext context) {
return
// Card(
// clipBehavior: Clip.antiAliasWithSaveLayer,
// elevation: 2,
// margin: EdgeInsets.all(10.0),
// shape: RoundedRectangleBorder(
// // side: BorderSide(color: AppColor.primaryColor, width: 2),
// borderRadius: BorderRadius.circular(15),
// ),
ClipRRect(
clipBehavior: Clip.antiAliasWithSaveLayer,
// elevation: 2,
// margin: EdgeInsets.all(10.0),
borderRadius: BorderRadius.all(Radius.circular(10)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
color: AppColor.primaryColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
flex: 1,
child: SvgPicture.asset(
AppImages.pharmacies,
color: AppColor.backgroundWhite,
width: 40,
height: 40,
),
),
SizedBox(
width: 5,
),
Expanded(
flex: 5,
child: Text(
widget.pharmacies.name ?? "",
// overflow: TextOverflow.fade,
maxLines: 2,
// softWrap: false,
style: GoogleFonts.comfortaa(
color: Colors.white, fontSize: 18),
),
),
Spacer(),
Expanded(
flex: 1,
child: GestureDetector(
onTap: () {
widget.onTap();
},
child: widget.remove
? Icon(
Icons.remove_circle_outline,
color: AppColor.backgroundWhite,
size: 40,
)
: SvgPicture.asset(
AppImages.right_arrow_circle,
color: AppColor.backgroundWhite,
width: 40,
height: 40,
),
),
),
],
),
),
),
Container(
height: 5,
color: AppColor.secondaryColor,
),
Container(
padding: EdgeInsets.all(5.0),
color: AppColor.primaryBackground,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 5,
height: 5,
),
Text(widget.pharmacies.addressLine1 ?? "",
style: GoogleFonts.comfortaa(
color: AppColor.primaryColor, fontSize: 14)),
Row(
children: [
Text(widget.pharmacies.city + ", ",
style: GoogleFonts.comfortaa(
color: AppColor.primaryColor,
fontSize: 14)),
Text(widget.pharmacies.stateCode + " ",
style: GoogleFonts.comfortaa(
color: AppColor.primaryColor,
fontSize: 14)),
Text(widget.pharmacies.zip,
style: GoogleFonts.comfortaa(
color: AppColor.primaryColor,
fontSize: 14)),
],
),
SizedBox(
width: 5,
height: 5,
),
// widget.pharmacies.telecom !=null ? GestureDetector(
// onTap: () => dialNo(widget.pharmacies.telecom),
// child: Row(
// children: [
// Text(
// widget.pharmacies.telecom,
//
// style: TextStyle(fontSize: 16,color: AppColor.primaryColor,),
// ),
//
// SvgPicture.asset(
// AppImages.call_text,
// height: 20,
// color: AppColor.primaryColor,
// ),
// ],
// ),
// ) : SizedBox(),
phoneNoWidget(
widget.pharmacies.telecom,
AppColor.primaryColor,
),
enableMessageDebugging
? Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"UUID:",
textAlign: TextAlign.end,
style: TextStyle(
color: AppColor.primaryColor,
fontSize: 16),
),
SizedBox(
width: 10,
),
Text(
widget.pharmacies.uuid,
style: TextStyle(fontSize: 16),
)
],
)
: SizedBox(),
widget.removeBottom
? SizedBox(
height: 0,
)
: Column(
children: [
SizedBox(
height: 5,
),
Container(
height: 5,
color: AppColor.primaryColor,
),
SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.all(5.0),
child: Row(
children: [
Text(
widget.pharmacies.distanceInMiles
.toStringAsFixed(1) +
" Miles Away",
style: GoogleFonts.comfortaa(
fontSize: 18,
color: AppColor.secondaryColor),
),
Spacer(),
// Text(
// Strings.delivery_partner,
// style: GoogleFonts.comfortaa(fontSize: 18),
// )
Image.asset(
AppImages.lyft_logo,
width: 25,
height: 17,
alignment: Alignment.bottomRight,
)
],
),
)
],
)
],
),
),
Container(
height: 5,
color: AppColor.primaryColor,
),
Container(
// decoration: BoxDecoration(
// image: DecorationImage(
// image: AssetImage(AppImages.map), fit: BoxFit.cover),
// ),
height: MediaQuery.of(context).size.height / 4,
width: MediaQuery.of(context).size.width,
child: SafeArea(
child: Container(
color: Colors.blueGrey.withOpacity(.8),
child: Center(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height / 4,
width: MediaQuery.of(context).size.width,
child: GoogleMap(
initialCameraPosition: CameraPosition(target: LatLng(widget.pharmacies.latitude,widget.pharmacies.longitude), zoom: 15),
markers: <Marker>{
Marker(
markerId: MarkerId("location"),
position: LatLng(
widget.pharmacies.latitude,
widget.pharmacies.longitude,
),
infoWindow: InfoWindow(
title: "location",
snippet: '*',
),
),
},
mapType: MapType.normal,
// onMapCreated: _onMapCreated,
myLocationButtonEnabled: false,
),
) ,
],
),
),
),
),
),
Container(
height: 5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10.0),
bottomRight: Radius.circular(10.0),
),
color: AppColor.primaryColor,
),
)
],
),
],
));
}
}
these are the some pictures of the issues
above is the ss of actual screen, adding ss for issues when we scroll it
I get to know today. Using Clip.antiAliasWithSaveLayer is costly.
There are enum property which define what it cost.
After investing many days i got to know antiAliasWithSaveLayer is very expensive to use.
hardEdge, which is the fastest clipping, but with lower fidelity.
antiAlias, which is a little slower than hardEdge, but with smoothed edges.
antiAliasWithSaveLayer, which is much slower than antiAlias, and should rarely be used.
Visit here for more information

How can I expand this Stack Widget?

here I am face a issue in Stack Widget. When I am give height width then The scaffold is scrolled. When I am remove the height Scaffold not scrolled. But in body I give
SingleChildScrollView().
..
I hope, Here I found my solution. Thanks......................................
This is custom Container Widget:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hexcolor/hexcolor.dart';
Widget customContainerWidget({
required Widget child,
double? height,
Color? color,
BorderRadiusGeometry? borderRadius,
}) {
return Container(
// height: height,
width: Get.width,
decoration: BoxDecoration(
color: color != null ? color : HexColor('#FFE58F'),
borderRadius:
borderRadius != null ? borderRadius : BorderRadius.circular(40),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 120,
spreadRadius: .10,
offset: Offset(1, 20),
),
],
),
child: ListView(
shrinkWrap: true,
primary: false,
children: [child],
),
);
}
This is my page Widget :
import 'package:Darucheeni/src/controllers/mainController/baseController.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:Darucheeni/src/configs/appColors.dart';
import 'package:Darucheeni/src/configs/appConfigs.dart';
import 'package:Darucheeni/src/widgets/button/customBackButton.dart';
import 'package:Darucheeni/src/widgets/ConatinerWidget/customBorderContainer.dart';
import 'package:Darucheeni/src/widgets/ConatinerWidget/customContainerWidget.dart';
import 'package:Darucheeni/src/widgets/textWidget/kText.dart';
class AcceptOrderPage extends StatelessWidget with BaseController {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
sizeH20,
Container(
//height: 3000, when I am give here Height then the Screen scrolled.
width: Get.width,
child: Stack(
clipBehavior: Clip.none,
children: [
Card(
elevation: 10,
margin: EdgeInsets.all(0),
child: Container(
height: 120,
width: Get.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
yellow,
green,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Padding(
padding: EdgeInsets.only(bottom: 20, left: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
customBackButton(),
KText(
text: 'Accept Order',
fontSize: 35,
fontFamily: brushScriptFonts,
color: black,
),
Container(),
],
),
),
),
),
Positioned(
top: 100,
left: 20,
right: 20,
child: customContainerWidget(
// height: 400,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 50,
),
child: Column(
children: [
ListView.builder(
shrinkWrap: true,
primary: false,
itemCount: productOrderC.productOrderList.length,
itemBuilder: (context, index) {
final item =
productOrderC.productOrderList[index];
return Padding(
padding: EdgeInsets.only(bottom: 30),
child: customBorderContainer(
child: customOrderHistory(
// onTap: () => Get.to(OrderCheckDetailsPage(
// allOrders: item,
// )),
onTap: () {},
orderId: '${item.trackingId}',
deliveryAddress: '23/A, Mirpur-10,Dhaka',
orderTime: item.createdAt.toString(),
status: item.ordertype!.name.toString(),
),
),
);
},
),
],
),
),
),
),
],
),
),
SizedBox(height: 100),
],
),
),
);
}
Widget customOrderHistory({
required String? orderId,
required String deliveryAddress,
required String orderTime,
required String status,
required void Function()? onTap,
}) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 20,
),
child: Column(
children: [
Row(
children: [
KText(
text: 'Order ID : ',
color: black,
fontSize: 11,
fontWeight: FontWeight.bold,
),
SizedBox(width: 10),
KText(
text: '$orderId',
fontSize: 20,
letterSpacing: 1.80,
fontWeight: FontWeight.bold,
),
],
),
sizeH20,
Row(
children: [
KText(
text: 'Delivery Address : ',
color: black,
fontSize: 11,
fontWeight: FontWeight.bold,
),
SizedBox(width: 10),
KText(
text: deliveryAddress,
fontSize: 12,
fontWeight: FontWeight.bold,
),
],
),
sizeH20,
Row(
children: [
KText(
text: 'Time : ',
color: black,
fontSize: 11,
fontWeight: FontWeight.bold,
),
SizedBox(width: 10),
KText(
text: orderTime,
fontSize: 12,
fontWeight: FontWeight.bold,
),
],
),
sizeH20,
Row(
children: [
KText(
text: 'Status : ',
color: black,
fontSize: 11,
fontWeight: FontWeight.bold,
),
SizedBox(width: 10),
KText(
text: status,
fontSize: 12,
fontWeight: FontWeight.bold,
),
Spacer(),
GestureDetector(
onTap: onTap,
child: KText(
text: 'Check Details',
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
],
),
],
),
);
}
}
Try to use
Stack(
fit: StackFit.expanded,
…
);

Flutter IconButton Remove Padding on Left to Align with Title Texts

So far it just goes in the middle even with a padding Edge Inset set to zero and Box Constraints.
Row(children: [
Padding(
padding: const EdgeInsets.fromLTRB(
3, 3, 3, 6),
child: Container(
width: 150,
height: 30,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title Sub-title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontFamily:
'Roboto’,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(
0, 10, 0, 3),
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
),
],
),
Try with column tree and adjust your padding as you desire
import 'package:flutter/material.dart';
import 'package:so_test/screen/child_page.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool visible = true;
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
appBar: AppBar(
title: Text("Test obviously"),
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.green,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
child: Container(
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 10, 3, 0),
width: 150,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Sub Title",
textAlign: TextAlign.left,
maxLines: 2,
style: TextStyle(
height: 1.2,
fontSize: 12,
letterSpacing: 0.15,
color: Colors.black,
),
),
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: 5,
),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () {},
icon: Icon(
Icons.bookmark_border,
size: 20.0,
color: Colors.black,
),
),
Text(
"Author",
textAlign: TextAlign.left,
style: TextStyle(
height: 1.1,
fontFamily: 'Roboto Light',
fontSize: 8,
color: Colors.black,
),
),
],
),
],
),
),
));
}
}
Output:
You can keep the first Container in different column and create the separate column for below three children's.

Data Types in Flutter

Hi guys so I am working around a datatype that is "int" and "double"... but how do I pass it in the text such that I can have a parenthesis or bracket around my int like this; (260) and a currency or letters attached to my double like this; $20.00 or GHS15.00
any help
this is my code;
class FoodDetails {
final Color primaryColor, backColor;
final double width, productRate, productPrice;
final String productUrl, productName;
FoodDetails({
this.primaryColor,
this.backColor,
this.width,
this.productRate,
this.productUrl,
this.productName,
this.productPrice,
});
}
List<FoodDetails> demoFoods = [
FoodDetails(
productName: 'Burger + Fries',
productPrice: 20.00,
productRate: 3.5,
productUrl: 'assets/images/kfc1.png',
backColor: Colors.orange.shade600,
),
FoodDetails(
productName: 'Peperoni Pizza',
productPrice: 45.00,
productRate: 3.5,
productUrl: 'assets/images/pizza2.png',
backColor: Colors.orangeAccent.shade100,
),
FoodDetails(
productName: 'Sundae IceCream',
productPrice: 40.00,
productRate: 5.0,
productUrl: 'assets/images/regularsundae.png',
backColor: Colors.purple,
),
FoodDetails(
productName: 'Chicken Nuggets 2pcs.',
productPrice: 35.05,
productRate: 3.6,
productUrl: 'assets/images/kfc2.png',
backColor: Colors.amber.shade50,
),
];
this is where I am passing the datatypes just read and follow;
class FoodCard extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SizedBox(
width: SizeConfig.screenWidth,
height: getProportionateScreenHeight(220),
child: Column(
children: [
Expanded(
flex: 3,
child: PageView.builder(
onPageChanged: (value) {},
controller: PageController(
initialPage: 0,
),
itemCount: demoFoods.length,
itemBuilder: (context, index) => Container(
margin: EdgeInsets.only(right: 10),
width: SizeConfig.screenWidth,
decoration: BoxDecoration(
color: demoFoods[index].backColor,
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: AssetImage(demoFoods[index].productUrl),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
color: Colors.white70,
blurRadius: 4.0,
offset: Offset(3.0, 3.0),
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
width: double.infinity,
height: 70,
padding: EdgeInsets.symmetric(
horizontal: getProportionateScreenWidth(10),
vertical: getProportionateScreenHeight(5),
),
decoration: cardInfoDecoration,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
demoFoods[index].productName,
style: TextStyle(
color: CupertinoColors.white,
fontSize: 20,
fontWeight: FontWeight.w700),
),
Spacer(),
Container(
padding: const EdgeInsets.all(4.0),
decoration: likedWidgetDecoration,
child: Icon(
Icons.near_me,
size: 17.0,
color: kPrimaryColor,
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
Text(
demoFoods[index].productRate.toString(),
style: TextStyle(
fontSize: 17.5,
color: Colors.white,
),
),
SizedBox(
width: getProportionateScreenWidth(10)),
buildSmoothStarRating(index),
Spacer(),
Text(
demoFoods[index].productPrice.toString(),
style: TextStyle(
fontSize: 17.5,
),
),
],
),
),
],
),
),
],
),
),
),
),
],
),
);
}
You mean something like this?
var myInt = 42;
Text('\$$myInt ') // $42
Text('\$($myInt) ') // $(42)
Text('GHS$myInt ') // GHS42