Related
I need a little help with flutter. I want to make a screen with a condition. The condition is if we have data show that data from firebase but if we don't have data show a button that says add data. The codes below show data from firebase but when we have no data that shows nothing.
Here are my codes that show a black screen.
#override
Widget build(BuildContext context) {
return GetBuilder<MapLogic>(
builder: (mapLogic) => Scaffold(
// backgroundColor: Colors.red,
body: StreamBuilder<QuerySnapshot>(
stream:
FirebaseFirestore.instance.collection('collection').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data!.docs.isEmpty) {
return Padding(
padding: const EdgeInsets.only(top: 30),
child: InkWell(
onTap: () async {
generalController.focusOut(context);
Get.to(const AddNewVehicle());
},
child: Container(
height: 55,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Styles.primaryColor,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Styles.primaryColor.withOpacity(0.19),
blurRadius: 40,
spreadRadius: 0,
offset: const Offset(
0, 22), // changes position of shadow
),
],
),
child: const Center(
child: Text(
"Add A Vehicle",
// style: state.buttonTextStyle
),
),
),
),
);
} else {
return FadedSlideAnimation(
child: Wrap(
children:
List.generate(snapshot.data!.docs.length, (index) {
if (snapshot.data!.docs[index].get('driver_id') ==
mapLogic.currentDriverData?.get('id')) {
return Padding(
padding: const EdgeInsets.fromLTRB(15, 30, 15, 0),
child: InkWell(
onTap: () {},
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(19),
boxShadow: [
BoxShadow(
color: customThemeColor.withOpacity(0.19),
blurRadius: 40,
spreadRadius: 0,
offset: const Offset(
0, 22), // changes position of shadow
),
],
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: [
///---image
Hero(
tag:
'${snapshot.data!.docs[index].get('image')}',
child: Material(
child: Container(
height: 80,
width: 80,
decoration: const BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle),
child: ClipRRect(
borderRadius:
BorderRadius.circular(40),
child: Image.network(
'${snapshot.data!.docs[index].get('image')}',
fit: BoxFit.cover,
),
),
),
),
),
///---price
Expanded(
child: Align(
alignment:
Alignment.center,
child: Container(
width: 70,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(
19),
color:
customThemeColor),
child: Padding(
padding:
const EdgeInsets
.fromLTRB(
0, 2, 0, 2),
child: Center(
child: Text(
'\$${snapshot.data!.docs[index].get('dis_price')}',
style: state
.priceTextStyle!
.copyWith(
color: Colors
.white)),
),
),
),
),
),
],
),
],
),
),
))
],
),
),
),
),
);
} else {
return const SizedBox();
}
}),
),
beginOffset: const Offset(0, 0.3),
endOffset: const Offset(0, 0),
slideCurve: Curves.linearToEaseOut,
);
}
} else {
return Text(
'Record not found',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 20,
color: Colors.black,
fontWeight: FontWeight.w600),
);
}
}),
),
);
}
You can follow this pattern but I will suggest following docs' one
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
!snapshot.hasData) {
return Text("could not find any data");
}
if (snapshot.hasData) {...}
if (snapshot.hasError) return Text("error");
return CircularProgressIndicator();
}
As you can see, Actually I want to make the screen scrollable, In my Flutter project, on one screen I have used some rows, columns, and listview but when I scroll my screen this is not happening, while I have to take SingleChildScrollView but it didn't work. and I have tried replacing the column with Listview but it didn't work. I don't understand where is the problem, please give me a solution. and I have attached my code and share a screenshot of the app screen below.
it shows pixel error.
.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:movie_app/core/constants/constants.dart';
import 'package:movie_app/ui/views/movielist/movie_detail_view.dart';
class MovieListView extends StatefulWidget {
const MovieListView({Key? key}) : super(key: key);
#override
_MovieListViewState createState() => _MovieListViewState();
}
class _MovieListViewState extends State<MovieListView> {
int counter = 0;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Color(0xff070d2d),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Container(
child: Column(
children: [
_buildHeaderSection(),
_buildSearchBar(),
SizedBox(height: 30),
buildCategoriesSection(),
SizedBox(height: 20),
buildListCategories(),
SizedBox(height: 30),
_buildPopularTitle(),
SizedBox(height: 30),
_buildPopularSection(),
],
),
),
),
),
],
),
),
);
}
Widget _buildHeaderSection() {
return Container(
padding: EdgeInsets.fromLTRB(30.0, 80.0, 30.0, 60.0),
// color: Colors.red,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MovieDetailView()),
);
},
child: Text(
"Hi, Edwards!",
style: TextStyle(
fontSize: 25,
//fontWeight: FontWeight.bold,
color: Colors.white),
),
),
Stack(
children: [
new IconButton(
icon: Icon(Icons.notifications),
onPressed: () {
setState(() {
//counter = 0;
});
}),
counter != 0
? new Positioned(
left: 20,
top: 20,
child: new Container(
padding: EdgeInsets.all(2),
decoration: new BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(6),
),
constraints: BoxConstraints(
minWidth: 14,
minHeight: 14,
),
child: Text(
'$counter',
style: TextStyle(
color: Colors.white,
fontSize: 8,
),
textAlign: TextAlign.center,
),
),
)
: new Container(),
ClipRRect(
borderRadius: BorderRadius.circular(50.0),
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ9CbZTM7W7VmNIGF36hIjpJcVoWEhbPGEGSw&usqp=CAU",
height: 50.0,
width: 50.0,
),
),
],
)
],
),
);
}
Widget _buildSearchBar() {
return Container(
height: 50,
margin: EdgeInsets.only(left: 30, right: 30),
child: TextField(
decoration: InputDecoration(
prefixIcon: Icon(
Icons.search,
color: Colors.white,
),
hintText: "search your movie",
hintStyle: TextStyle(color: Colors.white),
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.white,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.grey,
width: 2.0,
),
),
)),
);
}
Widget buildCategoriesSection() {
return Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
children: [
Text(
"Categories",
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
),
SizedBox(
width: 150,
),
Text(
"See more",
style: TextStyle(
color: Colors.grey,
fontSize: 15,
),
)
],
),
);
}
Widget buildListCategories() {
return Container(
height: 80,
padding: EdgeInsets.only(left: 20),
width: MediaQuery.of(context).size.width,
child: Container(
child: ListView.builder(
itemCount: categoryList.length,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context, position) {
return _buildCategoryItem(categoryList[position]);
},
),
),
);
}
Widget _buildCategoryItem(String category) {
return Container(
height: 80,
width: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.red.withOpacity(0.3),
),
margin: EdgeInsets.only(right: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.adb, color: Colors.white,),
SizedBox(height: 8),
Text(
category,
style: TextStyle(color: Colors.white),
),
],
),
);
}
_buildPopularTitle() {
return Container(
padding: EdgeInsets.only(left: 20, right: 20),
child: Row(
children: [
Text(
"Popular",
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
),
SizedBox(
width: 150,
),
Text(
"See more",
style: TextStyle(
color: Colors.grey,
fontSize: 15,
),
)
],
),
);
}
_buildPopularSection() {
return Container(
height: 200,
padding: EdgeInsets.only(left: 20),
width: MediaQuery.of(context).size.width,
child: Container(
child: ListView.builder(
itemCount: 6,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context, position) {
return _buildPopularItem();
},
),
),
);
}
_buildPopularItem() {
return Column(
children: [
Container(
height: 200,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red,
),
margin: EdgeInsets.only(right: 16),
child: Image.network(
'https://d1csarkz8obe9u.cloudfront.net/posterpreviews/movie-poster-template-design-21a1c803fe4ff4b858de24f5c91ec57f_screen.jpg?ts=1574144362',
fit: BoxFit.cover,
),
),
SizedBox(height: 5,),
Container(
color: Colors.green,
child: Text("data",style: TextStyle(
color: Colors.red
),
),
),
],
);
}
}
As you have mentioned SingleChildScrollView should work, but your problem is that you don't have enough items to be scrolled according to your screenshot.
So please use enough items and try again.
And in your _buildPopularItem() widget, decrease the container width, that's why it says pixel overflow.
This overflow is made from _buildPopularTitle() while you set fixed height from _buildPopularSection having height: 200,
if you look closely, inside _buildPopularItem
There is a Container with height: 200, and it is taking full height, so for rest of children SizedBox h:5 and Container Text aren't having any spaces here, and creating overflow.
Solutions
increase the height of _buildPopularSection
reduce the container height inside _buildPopularItem
wrap with FittedBox(child: _buildPopularItem());
From the screenshot I can see that your container is smaller by 21 pixels in height. Please increase it.
_buildPopularSection() {
return Container(
height: 230,
padding: EdgeInsets.only(left: 20),
width: MediaQuery.of(context).size.width,
child: Container(
child: ListView.builder(
itemCount: 6,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemBuilder: (context, position) {
return _buildPopularItem();
},
),
),
);
}
_buildPopularItem() {
return Column(
children: [
Container(
height: 225,
width: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.red,
),
margin: EdgeInsets.only(right: 16),
child: Image.network(
'https://d1csarkz8obe9u.cloudfront.net/posterpreviews/movie-poster-template-design-21a1c803fe4ff4b858de24f5c91ec57f_screen.jpg?ts=1574144362',
fit: BoxFit.cover,
),
),
SizedBox(height: 5,),
Container(
color: Colors.green,
child: Text("data",style: TextStyle(
color: Colors.red
),
),
),
],
);
}
Replace the above code and it should work...
I'm using a custom model's list in listview with 3 fields and when one of the field on any index changes in list, the listview doesn't reflect those changes even if i use setState() method to change the item.
So what to do?
Can i manually refresh listview in flutter?
In below code, in onSelectedItemChanged method i setState to change one of the answer in passed index in listQuestion and it does change the value in list i have checked that with debugging but just the listview doesn't refresh.
Dialog for picker :
showPicker(BuildContext context, int index) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return AlertDialog(
elevation: 80,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25))),
content: new Container(
height: 170,
width: MediaQuery.of(context).size.width,
alignment: Alignment.center,
decoration: BoxDecoration(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 120,
child: CupertinoPicker(
onSelectedItemChanged: (value) {
setState(() {
listQuestions[index].answer =
type_string[value].toString();
});
_listViewKey.currentState.reassemble();
},
itemExtent: 34.0,
diameterRatio: 1,
scrollController:
FixedExtentScrollController(initialItem: 2),
children: type),
),
SizedBox(height: 20),
GestureDetector(
child: Text(
"Ok",
style: TextStyle(
color: MyColors.orange,
fontSize: 17,
fontWeight: FontWeight.w900),
),
onTap: () {
Navigator.of(context).pop();
},
)
],
),
),
);
});
},
);
}
ListView in another scaffold :
return Scaffold(
key: _listViewKey,
body: SafeArea(
child: new ListView.builder(
itemCount: listQuestions.length,
itemBuilder: (BuildContext ctxt, int Index) {
return new Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: displayWidth(context) * 0.08,
alignment: Alignment.topRight,
child: Text(
listQuestions[Index].id.toString(),
style: TextStyle(
color: MyColors.orange,
fontSize: displayWidth(context) * 0.07,
fontWeight: FontWeight.w900),
),
),
SizedBox(width: displayWidth(context) * 0.02),
Expanded(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(
displayWidth(context) * 0.015,
displayWidth(context) * 0.0,
displayWidth(context) * 0.0,
displayWidth(context) * 0.0,
),
child: Text(
listQuestions[Index].question.toString(),
style: TextStyle(
color: MyColors.white,
fontSize: displayWidth(context) * 0.04,
fontWeight: FontWeight.w900),
),
),
Index > 7
? Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: MyColors.white,
borderRadius: BorderRadius.all(
Radius.circular(20))),
child: TextFormField(
maxLines: 3,
decoration: InputDecoration(
hintText: "Add your comments",
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none),
))
: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: MyColors.white,
borderRadius: BorderRadius.all(
Radius.circular(20))),
child: GestureDetector(
child: Text(listQuestions[Index]
.answer
.toString()),
onTap: () {
showPicker(context, Index);
},
),
)
],
))
],
),
),
);
})
))
I have the following view.
I would like the "confirm" button to always appear at the bottom of the slide up panel no matter what device is being used. If I position at the bottom correctly using padding or empty containers it is cut off on smaller screen size. Or if I position correctly on a smaller screen I am now running into issues with white space at the bottom. I am using the safe area widget which I thought ensured all widgets stay within the SafeArea?
Here is my code so far:
class ChooseAppointmentView extends StatefulWidget {
#override
_ChooseAppointmentViewState createState() => _ChooseAppointmentViewState();
}
class _ChooseAppointmentViewState extends State<ChooseAppointmentView> {
final List<Appointment> appointmentList = [
Appointment("Monday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Tuesday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Wednesday", DateTime.now(), DateTime.now(), "PM"),
Appointment("Thursday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Friday", DateTime.now(), DateTime.now(), "PM"),
];
DateTime _dateSelected = DateTime.now();
DateTime _initialiseDate = DateTime.now();
#override
Widget build(BuildContext context) {
BorderRadiusGeometry radius = BorderRadius.only(
topLeft: Radius.circular(24.0),
topRight: Radius.circular(24.0),
);
return BaseView<ConfirmDetailsViewModel>(
builder: (context, model, child) => Scaffold(
backgroundColor: AppColours.primaryColour,
body: SafeArea(
child: WillPopScope(
onWillPop: () async {
return false;
},
child: SlidingUpPanel(
maxHeight: MediaQuery.of(context).size.height * .80,
minHeight: 75.0,
parallaxEnabled: true,
parallaxOffset: .5,
panel: Stack(
children: <Widget>[
Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
child: Text(
"Select a date in here.",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 24.0,
),
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 200,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
minimumDate: _initialiseDate,
maximumDate: _initialiseDate.add(Duration(days: 7)),
initialDateTime: _initialiseDate,
onDateTimeChanged: (dateSelected) {
setState(() {
_dateSelected = dateSelected;
});
},
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 50.0,
width: MediaQuery.of(context).size.width - 50,
child: RaisedButton(
onPressed: () async {
//await model.submit();
Navigator.push(
context,
SizeRoute(
page: ChooseAppointmentView(),
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
child: Text('Confirm'),
color: AppColours.primaryLightColour,
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(9, 9, 9, 9),
),
),
],
),
),
],
),
collapsed: Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
decoration: BoxDecoration(
color: Colors.white, borderRadius: radius),
child: Center(
child: Text(
"Select a different date",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 20.0,
),
),
),
),
],
),
),
body: Container(
decoration: BoxDecoration(color: Colors.white),
child: ListView.builder(
padding: EdgeInsets.only(bottom: 100.0),
itemCount: appointmentList.length,
itemBuilder: (BuildContext context, int index) =>
buildAppointmentCards(context, index),
),
),
borderRadius: radius,
),
),
),
),
);
}
Widget buildAppointmentCards(BuildContext context, int index) {
final appointment = appointmentList[index];
return Padding(
padding: const EdgeInsets.all(10.0),
child: Material(
color: Colors.white.withOpacity(0.0),
child: InkWell(
splashColor: Colors.red,
onTap: () {
print('card tapped');
},
child: new Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
gradient: LinearGradient(
colors: [
AppColours.primaryColour,
AppColours.primaryLightColour,
AppColours.primaryLighterColour,
//add more colors for gradient
],
begin: Alignment.topLeft, //begin of the gradient color
end: Alignment.bottomRight, //end of the gradient color
stops: [0, 0.2, 0.5] //stops for individual color
//set the stops number equal to numbers of color
),
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Container(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: Row(
children: <Widget>[
Text(
appointment.day,
style:
TextStyle(fontSize: 30.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 80.0),
child: Row(
children: <Widget>[
Text(
"${DateFormat('hh:mm').format(appointment.date).toString()} - ${DateFormat('hh:mm').format(appointment.date).toString()}",
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: <Widget>[
Text(
DateFormat(
'dd/MM/yyyy',
).format(appointment.date).toString(),
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
Text(
appointment.ampm,
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
],
),
)
],
),
),
),
),
),
),
);
}
}
[enter link description here][2]
I think you can use the Align widget for positioning your widget in Stack. For more information can see in this link in this link you will see examples including explanation in the video.
I have a Text widget and two buttons to increase or decrease the count. + button to increase the count and - button to decrease the count. And the count is displayed in a Text widget. When I debug, count is changing but the Text is not updating. Not getting any error as well. How to do this. Here is my code:
_showDetails(BuildContext context, String barcodeResult) {
return showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Container(
height: 350.0,
width: 200.0,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: 150.0,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
color: Colors.teal),
),
Positioned(
top: 50.0,
left: 94.0,
child: Container(
height: 90.0,
width: 90.0,
child: CircleAvatar(
ExactAssetImage(
'assets/images/user-image-default.png'),
),
),
)
],
),
SizedBox(
height: 20.0,
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
name,
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
description,
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Price : $price',
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
//splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.add,
color: Colors.white,
)),
onTap: () {
setState(() {
// count++;
count = count + 1;
print(count);
});
},
),
),
),
SizedBox(
width: 20,
),
Text(count.toString()),
SizedBox(
width: 20,
),
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
// splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.remove,
color: Colors.white,
)),
onTap: () {
setState(() {
//count--;
count = count - 1;
print(count);
});
},
),
),
),
],
),
],
),
),
);
});
}
Screenshot:
Here is the working code.
_showDetails(BuildContext context, String barcodeResult) {
return showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
child: Container(
height: 350.0,
width: 200.0,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: 150.0,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
color: Colors.teal),
),
Positioned(
top: 50.0,
left: 94.0,
child: Container(
height: 90.0,
width: 90.0,
child: CircleAvatar(
backgroundImage: ExactAssetImage(chocolateImage),
),
),
)
],
),
SizedBox(
height: 20.0,
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
name,
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
description,
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Price : \$${price * count}',
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
//splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.add,
color: Colors.white,
)),
onTap: () {
setState(() {
// count++;
count = count + 1;
print(count);
});
},
),
),
),
SizedBox(
width: 20,
),
Text(count.toString()),
SizedBox(
width: 20,
),
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
// splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.remove,
color: Colors.white,
)),
onTap: () {
setState(() {
//count--;
count = count - 1;
print(count);
});
},
),
),
),
],
),
],
),
),
);
});
});
}