Data Types in Flutter - 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

Related

How to change circularprogressindicator in Center

I'm having a little problem here, I want to map a circularprogressindicator in the middle of the page but it just appears in the top center of the page, how do I move it to the middle of the page, I've tried wrapping it using the Column widget but an error occurs. How do I solve this simple problem.
and one more how do I add a hintText in the dropdown as the default value, because the dropdown immediately takes the value 1.
Thank you.
note:
green color for dropdown case
red for circularprogressindicator cases
Here I attach the code.
class JadwalKuliah extends StatefulWidget {
const JadwalKuliah({super.key});
#override
State<JadwalKuliah> createState() => _JadwalKuliahState();
}
class _JadwalKuliahState extends State<JadwalKuliah> {
String? _selectedItem1;
List<int> listitems = [1, 2, 3, 4, 5, 6, 7, 8];
int semester = 1;
List<Datum> data = [];
#override
void initState() {
super.initState();
fetchData(semester);
}
fetchData(int smt) async {
final apiResponse = await JadwalKuliahProvider.getJadwalKuliah(smt);
setState(() {
data = (apiResponse);
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: CustomAppbar(
title: 'Jadwal Kuliah',
),
),
body: Center(
child: Padding(
padding: const EdgeInsets.only(
left: 14,
top: 14,
right: 14,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Header(),
listJadwal(),
],
),
),
),
);
}
Widget Header() {
return Container(
padding: const EdgeInsets.only(left: 12, right: 8),
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1,
2,
),
),
],
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
// hint: const Text('Pilih Semester'),
value: semester,
onChanged: (value) {
setState(
() {
semester = value!;
},
);
fetchData(value!);
},
hint: const SizedBox(
width: 150, //and here
child: Text(
"Pilih Semester",
style: TextStyle(color: Colors.grey),
),
),
items: listitems.map(
(itemone) {
return DropdownMenuItem(
value: itemone, child: Text(itemone.toString()));
},
).toList(),
),
),
);
}
Widget listJadwal() {
return FutureBuilder<List<Datum>>(
future: JadwalKuliahProvider.getJadwalKuliah(semester),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Expanded(
child: ListView.builder(
padding: const EdgeInsets.only(
top: 10,
),
physics: const BouncingScrollPhysics(),
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 14),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(
10,
),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1, 2), // changes position of shadow
),
],
),
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
// "Audit Bank Syariah (SPI)",
snapshot.data![index].nmMk.toString(),
style: bold6,
),
Text(
snapshot.data![index].dosenAjar!.nmDosen.toString(),
style: regular7,
),
Text(
// "Perbankan Syariah",
snapshot.data![index].prodi.toString(),
style: regular7,
),
const SizedBox(
height: 5,
),
Row(
children: [
Container(
height: 30,
width: 70,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.location_on_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
Text(
'A201',
// snapshot.data![index]
// .dosenAjar!.nmDosen
// .toString(),
style: bold6.copyWith(color: greyColor),
),
],
),
),
),
const SizedBox(
width: 10,
),
Container(
height: 30,
width: 120,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.watch_later_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
const SizedBox(
width: 3,
),
Text(
// snapshot
// .data![index].jamAwal
// .toString(),
'09:00',
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'-',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'12:00',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
],
),
),
),
const SizedBox(
width: 10,
),
SizedBox(
height: 30,
width: 100,
child: ElevatedButton.icon(
onPressed: () {},
icon: const Icon(
Icons.download,
size: 17,
color: Color(0xffCEE1FF),
),
label: Text(
'Materi',
style: bold6,
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff0062FF),
),
),
),
],
),
const SizedBox(
height: 10,
),
Container(
width: double.infinity,
height: 38,
child: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffC9F7F5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Absen",
style: bold5.copyWith(
color: const Color(
0xff1BC5BD,
),
),
),
),
),
],
),
),
);
}),
);
} else {
return Center(
child: CircularProgressIndicator(color: primaryColor),
);
}
},
);
In your listJadwal change CircularProgressIndicator to this:
} else {
return Expanded(
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
);
}
Try below code I have same issue occurred I resolve this following code:
SizedBox(
height: MediaQuery.of(context).size.height / 1.0,//change on your need
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
),
Try this, Column will use your full screen size to center the widget
body: Column(mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: CircularProgressIndicator(),
)
],),

Overlapping of detail that I want to show in my detail screen

#override
Widget build(BuildContext context) {
return InkWell(
onTap: ()
{
Navigator.push(context, MaterialPageRoute(builder: (c)=> HistoryDetailScreen(orderID: orderID)));
},
child: FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance
.collection("orders")
.doc(orderID)
.get(),
builder: (c, snapshot)
{
Map? dataMap;
if(snapshot.hasData)
{
dataMap = snapshot.data!.data()! as Map<String, dynamic>;
totalAmount = dataMap["totalAmount"].toString();
customerName = dataMap["orderBy"].toString();
}
return snapshot.hasData
?
Container(
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5,),
Text(
"ORDER ID: "+customerName.toString(),
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
SizedBox(height: 5),
Text(
"Total Amount: ₱" + totalAmount.toString(),
style: const TextStyle(
fontWeight: FontWeight.w500,
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
SizedBox(height: 5,),
Text(
"More Info >>",
style: const TextStyle(
color: Colors.grey,
fontSize: 13,
fontFamily: "Acme",
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white
),
padding: const EdgeInsets.all(5),
margin: const EdgeInsets.all(5),
height: itemCount! * 50,
child: Stack(
children: [
Padding(padding: EdgeInsets.all(10)),
ListView.builder(
itemCount: itemCount,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index)
{
Items model = Items.fromJson(data![index].data()! as Map<String, dynamic>);
return Align(
heightFactor: 0.3,
alignment: Alignment.topCenter,
child: placedOrderDesignWidget(model, context, seperateQuantitiesList![index]),
);
},
),
],
),
),
],
),
)
:Center(child: circularProgress(),);
},
),
);
}
}
Widget placedOrderDesignWidget(Items model, BuildContext context, seperateQuantitiesList)
{
return Container(
width: MediaQuery.of(context).size.width,
height: 110,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 3,
blurRadius: 3,
offset: Offset(0, 3), // changes position of shadow
),
],
),
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10.0), //add border radius
child: Image.network(model.thumbnailUrl!, width: 90, height: 90, fit: BoxFit.cover,),
),
const SizedBox(width: 10.0,),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Text(
model.name! + " x " + seperateQuantitiesList,
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Acme",
),
),
),
const SizedBox(
width: 5,
),
],
),
Text(
"₱ " + model.price.toString(),
style: TextStyle(fontSize: 16.0, color: Colors.blue),
),
],
),
),
],
),
),
);
}
I wanted to avoid the overlapping of data that being shown in my screen

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 to set a separate value for each category to open related categories in flutter

Hello respected developers! I am trying to set separate category value for each category but now when I click on Pizza category it shows pizza, and when I click on other categories like Sandwich, Burger or anything else. it show the same value as it was designed in a widget. How to set category value for each category screen to have its own and related value. Please help me. here is a portion of my code that need to be fixed I can do it with a hard code but if I have more than 10 categories my code will be too long. Thank you very much and I really appreciate your help.
import 'package:flutter/material.dart';
import 'package:zar/screen/categories.dart';
class TopCard extends StatefulWidget {
const TopCard({Key? key}) : super(key: key);
#override
State<TopCard> createState() => _TopCardState();
}
// TOP CARD CLASS STARTS HERE
class CardItem {
final String urlImage;
final String title;
final String subTitle;
const CardItem({
required this.urlImage,
required this.title,
required this.subTitle,
});
}
// TOP CARD WIDGETS STARTS HERE
Widget topCard({
required CardItem item,
required BuildContext context,
}) =>
Container(
width: 150,
child: Column(
children: [
Expanded(
child: AspectRatio(
aspectRatio: 2 / 2,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Material(
child: Ink.image(
image: NetworkImage(item.urlImage),
fit: BoxFit.cover,
child: InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Categories(
item: item,
),
),
),
),
),
),
),
),
),
const SizedBox(height: 4),
Text(
item.title,
style: const TextStyle(
color: Color(0xff5e35b1),
fontSize: 20,
fontWeight: FontWeight.bold),
),
Text(
item.subTitle,
style: const TextStyle(
color: Colors.redAccent,
),
),
],
),
);
class _TopCardState extends State<TopCard> {
// TOP CARD LIST VIEW STARTS HERE
List<CardItem> items = const [
CardItem(
urlImage:
'https://images.unsplash.com/photo-1542834369-f10ebf06d3e0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80',
title: 'PIZZA',
subTitle: '\$20',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1621852004158-f3bc188ace2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80',
title: 'SANDWICH',
subTitle: '\$7.99',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1534938665420-4193effeacc4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=871&q=80',
title: 'FRIES',
subTitle: '\$2.99',
),
CardItem(
urlImage:
'https://images.unsplash.com/photo-1585238341710-4d3ff484184d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=804&q=80',
title: 'BURGER',
subTitle: '\$5.99',
),
];
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 20),
height: 150,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: 4,
separatorBuilder: (constext, _) => const SizedBox(width: 16),
itemBuilder: (context, index) => topCard(
context: context,
item: items[index],
),
),
);
}
}
This is my home screen category
This is my Category screen that shows Pizza categories.
And again this is my Category screen that shows the same Pizza categories. And I want this to be different.
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 20),
height: 150,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: 4,
separatorBuilder: (constext, _) => const SizedBox(width: 16),
itemBuilder: (context, index) => topCard(
context: context,
item: items[index],
),
),
);
}
Here is my category screen code:
import 'package:flutter/material.dart';
import 'package:zar/widgets/top_card.dart';
class Categories extends StatelessWidget {
final CardItem item;
const Categories({Key? key, required this.item}) : super(key: key);
#override
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(
title: Text(item.title),
),
body: ListView(
children: [
Container(
height: 350,
width: double.infinity,
color: const Color(0xff673ab7),
child: Column(
children: [
AspectRatio(
aspectRatio: 3 / 2,
child: Image.network(item.urlImage),
),
Text(
item.title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold,
),
)
],
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1625395005224-0fce68a3cdc8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"Italian Chees and Beef",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$20"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1606502281004-f86cf1282af5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Special Mini Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"American Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$9.99"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1628840042765-356cda07504e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=580&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Paparoni Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"Maxcan Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$17.50"),
],
),
),
),
],
),
),
),
SizedBox(
height: height * 0.01,
),
Center(
child: Container(
height: 167,
child: Stack(
children: [
Positioned(
child: Material(
child: Container(
margin: const EdgeInsets.all(5),
height: 300,
width: width * 0.9,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: const Color(0xff5e35b1).withOpacity(0.3),
blurRadius: 6.0,
offset: const Offset(4, 8),
),
],
),
),
),
),
Positioned(
top: 6,
left: 5,
child: Card(
elevation: 10.0,
shadowColor: const Color(0xff5e35b1).withOpacity(0.3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 150,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
"https://images.unsplash.com/photo-1585828922344-85c9daa264b0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=640&q=80"),
)),
),
),
),
Positioned(
top: 15,
left: 180,
child: Container(
height: 150,
width: 180,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Mashroom Pizza",
style: TextStyle(
color: Color(0xff5e35b1),
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
Text(
"European Pizza",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Divider(
color: Color(0xff5e35b1),
),
],
),
),
),
Positioned(
top: 120,
left: 180,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Rating",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("4.5"),
],
),
),
),
Positioned(
top: 120,
left: 350,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Price",
style: TextStyle(
color: Colors.redAccent,
fontSize: 20,
),
),
Text("\$15.99"),
],
),
),
),
],
),
),
),
],
),
);
}
}
And here is my home screen code.
import 'package:flutter/material.dart';
import 'package:zar/widgets/top_card.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Home"),
),
body: Container(
child: Column(
children: const [
TopCard(),
],
),
),
);
}
}