flutter problem: dataColumn width issue and How to remove rowDivider from dataTable? - flutter

here i got width issue for data table and I also want every rowDivider will be remove,
and here I use animation, if you have any idea to improve animation then tell me.
here i got width issue for data table and I also want every rowDivider will be remove,
and here I use animation, if you have any idea to improve animation then tell me.
this is my full code
import 'package:bonanza_flutter/Constants/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double _height = 60.0;
bool _isExpanded = false;
Future<bool> _showList() async {
await Future.delayed(Duration(milliseconds: 300));
return true;
}
Future<bool> _showList1() async {
await Future.delayed(Duration(milliseconds: 10));
return true;
}
bool isOnPMS = true;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
),
body: SingleChildScrollView(
child: Column(
children: [
// imageSlider(),
pmsData(),
// advantages(),
// products(),
Container(
height: 20,
)
],
),
),
);
}
}
extension WidgetExtension on _HomePageState {
pmsData() {
return Container(
color: lightBlue,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Column( crossAxisAlignment: CrossAxisAlignment.start,children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"PMS",
style:
TextStyle(fontSize: tSize16, fontWeight: FontWeight.w500),
),
Row(
children: [
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.arrow_back_ios_outlined,
color: Colors.white,
size: 17,
),
),
SizedBox(
width: 20,
),
Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.arrow_forward_ios_rounded,
color: Colors.white,
size: 17,
),
),
],
)
],
),
SizedBox(
height: 8,
),
Text(
"ICICI Prudential PMS",
style: TextStyle(
fontSize: tSize14, fontWeight: FontWeight.w500, color: skyBlue),
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\u{20B9} 50,00,000",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"ICICI Prudential PMS",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
SizedBox(
height: 14,
),
Text(
"\u{20B9} 2,02,993 (+4.06%)",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: green2Color),
),
SizedBox(
height: 5,
),
Text(
"Gains & Loss",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\u{20B9} 52,02,993",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"Current Market Value",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
SizedBox(
height: 14,
),
Text(
"\u{20B9} 5",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: blackColor),
),
SizedBox(
height: 5,
),
Text(
"Total Holdings",
style: TextStyle(
fontSize: tSize11,
fontWeight: FontWeight.w500,
color: greyColor),
),
],
),
SizedBox(
width: 0,
)
],
),
],),
),
AnimatedContainer(
duration: Duration(milliseconds: 300),
height: _height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
),
// padding: EdgeInsets.only(left: 15, right: 15),
child: Column(
children: [
_isExpanded
? SizedBox.shrink()
: FutureBuilder(
future: _showList1(),
/// will wait untill box animation completed
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SizedBox();
}
return Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0, bottom: 00, left: 70, right: 70),
child: SizedBox(
height: 25,
width: 100,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: skyBlue,
shadowColor: Colors.transparent),
onPressed: () {
setState(() {
isOnPMS = !isOnPMS;
if (!_isExpanded) {
setState(() {
_height = 350;
_isExpanded = true;
});
} else {
setState(() {
_height = 50;
_isExpanded = false;
});
}
});
print(_isExpanded);
},
child: Text("View More"),
),
),
),
);
}),
_isExpanded
? FutureBuilder(
future: _showList(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SizedBox();
}
return Padding(
padding: const EdgeInsets.only(
top: 20.0, bottom: 00, left: 0, right: 0),
child: Column(
children: [
DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text(
'#',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'STOCK',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'SECTOR',style: TextStyle(color: Colors.white),
),
),
DataColumn(
label: Text(
'WEIGHT',style: TextStyle(color: Colors.white),
),
),
],
rows: const <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(Text('1')),
DataCell(Text('TCS')),
DataCell(Text('Global')),
DataCell(Text('11%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('2')),
DataCell(Text('DMART')),
DataCell(Text('Consumers')),
DataCell(Text('10%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('3')),
DataCell(Text('ICICIBANK')),
DataCell(Text('Financials')),
DataCell(Text('12%')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('4')),
DataCell(Text('RELIANCE')),
DataCell(Text('Industrial')),
DataCell(Text('13%')),
],
),
],
dividerThickness: 0,
headingRowColor:
MaterialStateColor.resolveWith(
(states) => greyColor),
headingRowHeight: 30,
),
Center(
child: Padding(
padding: const EdgeInsets.only(
top: 20.0,
bottom: 00,
left: 70,
right: 70),
child: SizedBox(
height: 25,
width: 100,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: skyBlue,
shadowColor: Colors.transparent),
onPressed: () {
setState(() {
isOnPMS = !isOnPMS;
if (!_isExpanded) {
setState(() {
_height = 350;
_isExpanded = true;
});
} else {
setState(() {
_height = 50;
_isExpanded = false;
});
}
});
print(_isExpanded);
},
child: const Text('View Less'),
),
),
),
)
],
),
);
})
: SizedBox.shrink(),
],
),
)
],
),
);
}
}
I want like this dataDable.
this is my ui which I created.

Wrap DataTable with SingleChildScrollView and set scrollDirection to horizontal.
Use TableBorder to remove divider.

Related

Flutter ; Vertical ListView inside a column(inside another column) causing an overflow

class Episodes extends StatefulWidget {
const Episodes({super.key});
#override
State<Episodes> createState() => _EpisodesState();
}
class _EpisodesState extends State<Episodes> {
final seasons = ['Season 1', 'Season 2', 'Season 3'];
String? value;
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
//EdgeInsets.only(left: size.width * 0.03, right: size.width * 0.03),
return SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Column(
children: [
Container(
height: size.height * 0.045,
width: size.width * 0.25,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.25),
borderRadius: BorderRadius.circular(5)),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: value,
alignment: Alignment.center,
isExpanded: true,
//icon: Icon(Icons.arrow_drop_down_outlined,
// size: 12, color: Colors.white),
iconEnabledColor: Colors.white,
//dropdownColor: Colors.transparent,
items: seasons.map(buildMenuItem).toList(),
dropdownColor: Colors.grey.withOpacity(0.3),
onChanged: (value) => setState(() {
this.value = value;
}),
),
),
),
SizedBox(height: size.height * 0.02),
ListView.builder(
shrinkWrap: true,
//physics: const AlwaysScrollableScrollPhysics(),
itemCount: 15,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Container(
color: Colors.red,
height: 15,
width: 15,
),
);
},
),
],
),
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Center(
child: Text(
item,
style: GoogleFonts.poppins(color: Colors.white, fontSize: 12),
),
));
}
Im trying to build a netflix clone, and this is the design of the episode list in the title page.
Basically, im trying to include listview.builder(vertical) inside a column; but im getting an overflow error.
This column is furthur getting returned as one of the children of a parent column in another file.
Till now ive tried wrapping the column under :
*SingleChildScrollView,
*Expanded
*SizedBox, Container : with fixed height
None of the above worked; i even tried playing around with the scroll physics, didnt work, the overflow error still persisted.
Im new to flutter; i just wanna get rid of the overflow error. Any help will be appreciated!
Furthur im looking to dynamically fetch details from firebase and display them here. Any tips on that will be appreciated as well!
Main file structure :
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:netflixclone/ContentPages/tabbar_pg.dart';
import 'package:video_player/video_player.dart';
//UpperNavBar
//video preview
//Container
//Name
//{List of particulars}
//Play Btn
//Download Btn
//Description
//Strarring
//creator
//Row List : List, Rate, Share, Download S1.
//Tab Bar : Episodes, TrailersNMore, MoreLikeThis
//DropDownList : Seasons list
//Episodes : E1 : Container :{}..
//TrailersNMore : Vidoes
//MoreLikeThis : 9 random suggestions. : if i can ill do.
class TitlePage extends StatefulWidget {
const TitlePage({super.key});
#override
State<TitlePage> createState() => _TitlePageState();
}
class _TitlePageState extends State<TitlePage> {
int current = 0;
#override
Widget build(BuildContext context) {
List<String> items = [
"EPISODES",
"TRAILERS & MORE",
"MORE LIKE THIS",
];
List<Widget> itemsPages = [
Episodes(),
TrailersNMore(),
MoreLikeThis(),
];
Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(size.height * 0.05),
child: UpperAppBar(),
),
backgroundColor: Colors.black,
body: Padding(
padding: EdgeInsets.only(top: size.height * 0.007),
child: Column(
children: [
Container(child: VideoController()),
Container(
child: Padding(
padding: EdgeInsets.only(
left: size.width * 0.02,
top: size.height * 0.01,
right: size.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Peaky Blinders",
style: GoogleFonts.comfortaa(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.w900)),
Padding(
padding: EdgeInsets.only(top: size.height * 0.008),
child: Row(
children: [
Text("2022",
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 16,
fontWeight: FontWeight.w500)),
SizedBox(width: size.width * 0.03),
Container(
width: size.width * 0.033,
height: size.height * 0.024,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.5)),
child: Center(
child: Text("A",
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 16,
fontWeight: FontWeight.w500)),
),
),
SizedBox(width: size.width * 0.03),
Text("6-Seasons",
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 16,
fontWeight: FontWeight.w500)),
SizedBox(width: size.width * 0.03),
Icon(Icons.comment_rounded,
size: 25, color: Colors.white.withOpacity(0.8))
],
),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.white),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
),
fixedSize: MaterialStateProperty.all<Size>(
Size.fromWidth(size.width))),
onPressed: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.play_arrow,
color: Colors.black,
size: 22,
),
SizedBox(width: size.width * 0.01),
Text('Play',
style: GoogleFonts.poppins(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold))
]),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Colors.grey.withOpacity(0.25)),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
),
fixedSize: MaterialStateProperty.all<Size>(
Size.fromWidth(size.width))),
onPressed: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.download_outlined,
color: Colors.white,
size: 20,
),
SizedBox(width: size.width * 0.01),
Text('Download',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold)),
SizedBox(width: size.width * 0.01),
Text('S1:E1',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold)),
]),
),
Text(
'A notorious gang in 1919 Birminham, England, is led by the fierce Tommy Shelby, a crime boss set on moving up in the world no matter the cost.',
style: GoogleFonts.poppins(
color: Colors.white, fontSize: 12),
),
SizedBox(height: size.height * 0.01),
Row(
children: [
Text(
'Starring: ',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 12),
),
Text(
'Cillian Murphy,Sam Neill, Helen McCory',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 12),
),
GestureDetector(
onTap: () => null,
child: Text(
'...more',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 12),
),
),
],
),
Row(
children: [
Text(
'Creator: ',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.99),
fontSize: 12),
),
Text(
'Steven Knight',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 12),
),
],
),
SizedBox(height: size.height * 0.01),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.check,
color: Colors.white,
size: 30,
)),
Text(
'My List',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.thumb_up_alt_outlined,
color: Colors.white,
size: 30,
)),
Text(
'Rate',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.share,
color: Colors.white,
size: 30,
)),
Text(
'Share',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.download_rounded,
color: Colors.white,
size: 30,
)),
Text(
'Download Season 1',
style: GoogleFonts.poppins(
color: Colors.grey.withOpacity(0.7),
fontSize: 10),
)
],
),
),
],
)
],
),
),
),
Divider(
height: size.height * 0.01,
),
Container(
color: Colors.grey.withOpacity(0.7),
height: size.height * 0.002,
),
//TabBar :
Padding(
padding: EdgeInsets.only(
left: size.width * 0.03, right: size.width * 0.03),
child: SizedBox(
width: double.infinity,
height: 60,
child: ListView.builder(
physics: const BouncingScrollPhysics(),
itemCount: items.length,
scrollDirection: Axis.horizontal,
itemBuilder: (ctx, index) {
return GestureDetector(
onTap: () => setState(() {
current = index;
}),
child: Padding(
padding: EdgeInsets.only(right: size.width * 0.1),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
decoration: BoxDecoration(
border: current == index
? Border(
top: BorderSide(
color: Color.fromARGB(255, 225, 26, 12),
width: size.height * 0.005),
)
: Border(
top: BorderSide(
color: Colors.black,
width: size.height * 0.005),
),
),
child: Text(items[index],
style: GoogleFonts.bebasNeue(
fontSize: 22,
fontWeight: FontWeight.w500,
color: current == index
? Colors.white
: Colors.grey.withOpacity(0.99))),
),
),
);
},
),
),
),
itemsPages[current],
//Episodes()
// Container(
// width: double.infinity,
// child: itemsPages[current],
// ),
],
),
),
);
}
Widget UpperAppBar() {
return AppBar(
backgroundColor: Colors.black,
leading: Icon(
Icons.arrow_back,
color: Colors.white,
size: 30,
),
actions: [
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
size: 30,
),
onPressed: null,
),
IconButton(
icon: Image.asset('assets/Images/ProfileImg.jpg', width: 30),
onPressed: null,
)
],
);
}
}
class VideoController extends StatefulWidget {
const VideoController({super.key});
#override
State<VideoController> createState() => _VideoPlayerState();
}
class _VideoPlayerState extends State<VideoController> {
late VideoPlayerController controller;
final asset = 'assets/Videos/SoClose-ThomasShelby.mp4';
#override
void initState() {
super.initState();
controller = VideoPlayerController.asset(asset)
..addListener(() => setState(() {}))
..setLooping(
true) //if u can after vid finishes : pause it and add a peaky blinders logo
..initialize().then((_) => controller.play());
}
#override
void dispose() {
controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
final isMuted = controller.value.volume == 0;
return Stack(children: [
VideoPlayerWidget(controller: controller),
if (controller != null && controller.value.isInitialized)
Positioned(
top: size.height * 0.185,
left: size.width * 0.85,
child: IconButton(
icon: Icon(
isMuted ? Icons.volume_off : Icons.volume_up,
color: Colors.white,
size: 20,
),
onPressed: () => controller.setVolume(isMuted ? 1 : 0),
),
),
Positioned(
top: size.height * 0.205,
left: size.width * 0.02,
child: Container(
width: size.width * 0.16,
height: size.height * 0.026,
decoration: BoxDecoration(color: Colors.black.withOpacity(0.39)),
child: Center(
child: Text('Preview',
style: GoogleFonts.ptSans(color: Colors.white, fontSize: 15)),
),
),
)
]);
}
}
class VideoPlayerWidget extends StatelessWidget {
final VideoPlayerController controller;
const VideoPlayerWidget({
Key? key,
required this.controller,
}) : super(key: key);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return controller != null && controller.value.isInitialized
? Container(
alignment: Alignment.topCenter,
child: buildVideo(),
)
: Container(
height: 100,
child: Center(child: CircularProgressIndicator()),
);
}
Widget buildVideo() => Stack(children: <Widget>[
buildVideoPlayer(),
Positioned.fill(child: BasicOverlayWidget(controller: controller)),
]);
Widget buildVideoPlayer() => AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: VideoPlayer(controller));
}
class BasicOverlayWidget extends StatelessWidget {
final VideoPlayerController controller;
const BasicOverlayWidget({
Key? key,
required this.controller,
}) : super(key: key);
#override
Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () =>
controller.value.isPlaying ? controller.pause() : controller.play(),
child: Stack(
children: <Widget>[
buildPlay(),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: buildIndicator(),
),
],
),
);
Widget buildIndicator() => VideoProgressIndicator(
controller,
allowScrubbing: true,
colors: VideoProgressColors(
backgroundColor: Color.fromARGB(255, 115, 11, 3),
playedColor: Color.fromARGB(255, 225, 26, 12)),
);
Widget buildPlay() => controller.value.isPlaying
? Container()
: Container(
alignment: Alignment.center,
color: Colors.black26,
child: Icon(Icons.play_arrow, color: Colors.white, size: 80),
);
}
From what i understand you have something like this on the main page:
Column(children : [
SomeWidget(),
OtherWidget(),
Episodes(),
]);
Since Episodes() is in Column, it's been given infinite height. You should wrap it in an Expanded() widget if you want it to get the remaining height of the page, like below.
Column(children : [
SomeWidget(),
OtherWidget(),
Expanded(child:Episodes()),
]);
If this doesn't fix your problem, please give more informations about the parent widget (where Episodes is used).
The scaffold wrapper was missing and I fixed it
I added Area to prevent the height of the MenuItem popup from exceeding the top of the screen
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class Episodes extends StatefulWidget {
const Episodes({super.key});
#override
State<Episodes> createState() => _EpisodesState();
}
class _EpisodesState extends State<Episodes> {
final seasons = ['Season 1', 'Season 2', 'Season 3'];
String? value;
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
//EdgeInsets.only(left: size.width * 0.03, right: size.width * 0.03),
return SafeArea(
child: Scaffold(
body: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: Column(
children: [
Container(
height: size.height * 0.045,
width: size.width * 0.25,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.25),
borderRadius: BorderRadius.circular(5)),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: value,
alignment: Alignment.center,
isExpanded: true,
//icon: Icon(Icons.arrow_drop_down_outlined,
// size: 12, color: Colors.white),
iconEnabledColor: Colors.white,
//dropdownColor: Colors.transparent,
items: seasons.map(buildMenuItem).toList(),
dropdownColor: Colors.grey.withOpacity(0.3),
onChanged: (value) => setState(() {
this.value = value;
}),
),
),
),
SizedBox(height: size.height * 0.02),
ListView.builder(
shrinkWrap: true,
//physics: const AlwaysScrollableScrollPhysics(),
itemCount: 15,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Container(
color: Colors.red,
height: 15,
width: 15,
),
);
},
),
],
),
),
));
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Center(
child: Text(
item,
// style: GoogleFonts.poppins(color: Colors.white, fontSize: 12),
),
));
}
//UpperNavBar
//video preview
//Container
//Name
//{List of particulars}
//Play Btn
//Download Btn
//Description
//Strarring
//creator
//Row List : List, Rate, Share, Download S1.
//Tab Bar : Episodes, TrailersNMore, MoreLikeThis
//DropDownList : Seasons list
//Episodes : E1 : Container :{}..
//TrailersNMore : Vidoes
//MoreLikeThis : 9 random suggestions. : if i can ill do.
class TitlePage extends StatefulWidget {
const TitlePage({super.key});
#override
State<TitlePage> createState() => _TitlePageState();
}
class _TitlePageState extends State<TitlePage> {
int current = 0;
#override
Widget build(BuildContext context) {
List<String> items = [
"EPISODES",
"TRAILERS & MORE",
"MORE LIKE THIS",
];
List<Widget> itemsPages = [
Episodes(),
Expanded(
child: Column(
children: [
ListView(
shrinkWrap: true,
children: [
...List.generate(
10,
(index) => ListTile(
title: Text('$index'),
))
],
)
],
),
),
Expanded(
child: Column(
children: [
// TrailersNMore(),
// MoreLikeThis(),
],
))
];
Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(size.height * 0.05),
child: UpperAppBar(),
),
backgroundColor: Colors.black,
body: Padding(
padding: EdgeInsets.only(top: size.height * 0.007),
child: Column(
children: [
Container(child: VideoController()),
Container(
child: Padding(
padding: EdgeInsets.only(
left: size.width * 0.02,
top: size.height * 0.01,
right: size.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Peaky Blinders",
// style: GoogleFonts.comfortaa(
// color: Colors.white,
// fontSize: 30,
// fontWeight: FontWeight.w900),
),
Padding(
padding: EdgeInsets.only(top: size.height * 0.008),
child: Row(
children: [
Text(
"2022",
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 16,
// fontWeight: FontWeight.w500),
),
SizedBox(width: size.width * 0.03),
Container(
width: size.width * 0.033,
height: size.height * 0.024,
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.5)),
child: Center(
child: Text(
"A",
textAlign: TextAlign.center,
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 16,
// fontWeight: FontWeight.w500),
),
),
),
SizedBox(width: size.width * 0.03),
Text(
"6-Seasons",
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 16,
// fontWeight: FontWeight.w500),
),
SizedBox(width: size.width * 0.03),
Icon(Icons.comment_rounded,
size: 25, color: Colors.white.withOpacity(0.8))
],
),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.white),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
),
fixedSize: MaterialStateProperty.all<Size>(
Size.fromWidth(size.width))),
onPressed: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.play_arrow,
color: Colors.black,
size: 22,
),
SizedBox(width: size.width * 0.01),
Text(
'Play',
// style: GoogleFonts.poppins(
// color: Colors.black,
// fontSize: 16,
// fontWeight: FontWeight.bold),
)
]),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Colors.grey.withOpacity(0.25)),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
),
fixedSize: MaterialStateProperty.all<Size>(
Size.fromWidth(size.width))),
onPressed: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.download_outlined,
color: Colors.white,
size: 20,
),
SizedBox(width: size.width * 0.01),
Text(
'Download',
// style: GoogleFonts.poppins(
// color: Colors.white,
// fontSize: 16,
// fontWeight: FontWeight.bold)
),
SizedBox(width: size.width * 0.01),
Text(
'S1:E1',
// style: GoogleFonts.poppins(
// color: Colors.white,
// fontSize: 16,
// fontWeight: FontWeight.bold),
),
]),
),
Text(
'A notorious gang in 1919 Birminham, England, is led by the fierce Tommy Shelby, a crime boss set on moving up in the world no matter the cost.',
// style: GoogleFonts.poppins(
// color: Colors.white, fontSize: 12),
),
SizedBox(height: size.height * 0.01),
Row(
children: [
Text(
'Starring: ',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 12),
),
Text(
'Cillian Murphy,Sam Neill, Helen McCory',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 12),
),
GestureDetector(
onTap: () => null,
child: Text(
'...more',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 12),
),
),
],
),
Row(
children: [
Text(
'Creator: ',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.99),
// fontSize: 12),
),
Text(
'Steven Knight',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 12),
),
],
),
SizedBox(height: size.height * 0.01),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.check,
color: Colors.white,
size: 30,
)),
Text(
'My List',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.thumb_up_alt_outlined,
color: Colors.white,
size: 30,
)),
Text(
'Rate',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.share,
color: Colors.white,
size: 30,
)),
Text(
'Share',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 10),
)
],
),
),
InkWell(
splashColor: Colors.grey.withOpacity(0.8),
child: Column(
children: [
IconButton(
onPressed: () => null,
icon: Icon(
Icons.download_rounded,
color: Colors.white,
size: 30,
)),
Text(
'Download Season 1',
// style: GoogleFonts.poppins(
// color: Colors.grey.withOpacity(0.7),
// fontSize: 10),
)
],
),
),
],
)
],
),
),
),
Divider(
height: size.height * 0.01,
),
Container(
color: Colors.grey.withOpacity(0.7),
height: size.height * 0.002,
),
//TabBar :
Padding(
padding: EdgeInsets.only(
left: size.width * 0.03, right: size.width * 0.03),
child: SizedBox(
width: double.infinity,
height: 60,
child: ListView.builder(
physics: const BouncingScrollPhysics(),
itemCount: items.length,
scrollDirection: Axis.horizontal,
itemBuilder: (ctx, index) {
return GestureDetector(
onTap: () => setState(() {
current = index;
}),
child: Padding(
padding: EdgeInsets.only(right: size.width * 0.1),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
decoration: BoxDecoration(
border: current == index
? Border(
top: BorderSide(
color: Color.fromARGB(255, 225, 26, 12),
width: size.height * 0.005),
)
: Border(
top: BorderSide(
color: Colors.black,
width: size.height * 0.005),
),
),
child: Text(
items[index],
// style: GoogleFonts.bebasNeue(
// fontSize: 22,
// fontWeight: FontWeight.w500,
// color: current == index
// ? Colors.white
// : Colors.grey.withOpacity(0.99)),
),
),
),
);
},
),
),
),
itemsPages[current],
//Episodes()
// Container(
// width: double.infinity,
// child: itemsPages[current],
// ),
],
),
),
);
}
Widget UpperAppBar() {
return AppBar(
backgroundColor: Colors.black,
leading: Icon(
Icons.arrow_back,
color: Colors.white,
size: 30,
),
actions: [
IconButton(
icon: Icon(
Icons.search,
color: Colors.white,
size: 30,
),
onPressed: null,
),
IconButton(
icon: Image.asset('assets/Images/ProfileImg.jpg', width: 30),
onPressed: null,
)
],
);
}
}
class VideoController extends StatefulWidget {
const VideoController({super.key});
#override
State<VideoController> createState() => _VideoPlayerState();
}
class _VideoPlayerState extends State<VideoController> {
late VideoPlayerController controller;
final asset = 'assets/Videos/SoClose-ThomasShelby.mp4';
#override
void initState() {
super.initState();
controller = VideoPlayerController.asset(asset)
..addListener(() => setState(() {}))
..setLooping(
true) //if u can after vid finishes : pause it and add a peaky blinders logo
..initialize().then((_) => controller.play());
}
#override
void dispose() {
controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
final isMuted = controller.value.volume == 0;
return Stack(children: [
VideoPlayerWidget(controller: controller),
if (controller != null && controller.value.isInitialized)
Positioned(
top: size.height * 0.185,
left: size.width * 0.85,
child: IconButton(
icon: Icon(
isMuted ? Icons.volume_off : Icons.volume_up,
color: Colors.white,
size: 20,
),
onPressed: () => controller.setVolume(isMuted ? 1 : 0),
),
),
Positioned(
top: size.height * 0.205,
left: size.width * 0.02,
child: Container(
width: size.width * 0.16,
height: size.height * 0.026,
decoration: BoxDecoration(color: Colors.black.withOpacity(0.39)),
child: Center(
child: Text(
'Preview',
// style: GoogleFonts.ptSans(color: Colors.white, fontSize: 15),
),
),
),
)
]);
}
}
class VideoPlayerWidget extends StatelessWidget {
final VideoPlayerController controller;
const VideoPlayerWidget({
Key? key,
required this.controller,
}) : super(key: key);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return controller != null && controller.value.isInitialized
? Container(
alignment: Alignment.topCenter,
child: buildVideo(),
)
: Container(
height: 100,
child: Center(child: CircularProgressIndicator()),
);
}
Widget buildVideo() => Stack(children: <Widget>[
buildVideoPlayer(),
Positioned.fill(child: BasicOverlayWidget(controller: controller)),
]);
Widget buildVideoPlayer() => AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: VideoPlayer(controller));
}
class BasicOverlayWidget extends StatelessWidget {
final VideoPlayerController controller;
const BasicOverlayWidget({
Key? key,
required this.controller,
}) : super(key: key);
#override
Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () =>
controller.value.isPlaying ? controller.pause() : controller.play(),
child: Stack(
children: <Widget>[
buildPlay(),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: buildIndicator(),
),
],
),
);
Widget buildIndicator() => VideoProgressIndicator(
controller,
allowScrubbing: true,
colors: VideoProgressColors(
backgroundColor: Color.fromARGB(255, 115, 11, 3),
playedColor: Color.fromARGB(255, 225, 26, 12)),
);
Widget buildPlay() => controller.value.isPlaying
? Container()
: Container(
alignment: Alignment.center,
color: Colors.black26,
child: Icon(Icons.play_arrow, color: Colors.white, size: 80),
);
}

flutter issue: bottom overflowed by 57 pixels

Here my bottom preferredSize (preferredSize: Size.fromHeight(148.0)) in appBar.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
this is my code
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
import 'package:dropdown_button2/dropdown_button2.dart';
import 'dart:developer';
import '../../../APIMnager/APIManager.dart';
import '../../../APIMnager/preferences.dart';
import '../../../Constants/constants.dart';
import 'action_page.dart';
import 'holding_page.dart';
import 'overview_page.dart';
import 'report_page.dart';
class PMSListDataPage extends StatelessWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: ShowCaseWidget(
onStart: (index, key) {
log('onStart: $index, $key');
},
onComplete: (index, key) {
log('onComplete: $index, $key');
print("here me");
if (index == 0) {
Preferences.saveData("showCaseCount2", "2");
}
},
blurValue: 1,
builder: Builder(
builder: (context) => PMSListDataPage1(
panNum: panNum,
singlePMSData: singlePMSData,
allPMSListData: allPMSListData)),
autoPlayDelay: const Duration(seconds: 3),
),
);
}
}
class PMSListDataPage1 extends StatefulWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage1(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
_PMSListDataPage1State createState() => _PMSListDataPage1State();
}
class _PMSListDataPage1State extends State<PMSListDataPage1> {
var selectedValue;
ApiManager apiManager = ApiManager();
final GlobalKey _one = GlobalKey();
final GlobalKey _two = GlobalKey();
final GlobalKey _three = GlobalKey();
final scrollController = ScrollController();
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: DefaultTabController(
length: 4,
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back_ios_rounded),
onPressed: () {
Navigator.pop(context);
},
tooltip: '',
);
},
),
elevation: 0,
backgroundColor: skyBlue,
title: Text(
"PMS",
style: TextStyle(fontSize: tSize16),
),
actions: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IconButton(
icon: Image.asset(
"assets/phone_icon.png",
height: 25,
width: 25,
),
onPressed: () {
UrlLauncher.launch('tel:+91$UserRMNumber');
}))
],
)
],
bottom: PreferredSize(
preferredSize: Size.fromHeight(148.0),
child: Column(
children: [
Container(
color: skyBlue,
height: 90,
child:
nameView(widget.singlePMSData, widget.allPMSListData),
),
Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: TabBar(
overlayColor:
MaterialStateProperty.all(Colors.transparent),
indicatorColor: Colors.white,
unselectedLabelColor: lightBlue,
onTap: (v) {
searchHoldingsQuery.clear();
FocusScope.of(context).unfocus();
},
indicator: UnderlineTabIndicator(
borderSide: BorderSide(
color: Colors.white,
width: 3.2,
style: BorderStyle.solid),
insets: EdgeInsets.only(left: 30.0, right: 30)),
isScrollable: true,
labelColor: Colors.white,
tabs: [
Tab(
child: Text(
'OVERVIEW',
),
),
Tab(
child: Text(
'HOLDINGS',
),
),
Tab(
child: Text(
'REPORTS',
),
),
Tab(
child: Text(
'ACTIONS',
),
),
],
),
),
],
),
),
),
body:
TabBarView(physics: NeverScrollableScrollPhysics(), children: [
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: OverviewPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: HoldingPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ReportPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ActionPage(),
),
]),
)),
);
}
}
extension WidgetExtension on _PMSListDataPage1State {
nameView(singlePMSData, allPMSListData) {
return Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 5, bottom: 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
),
child: DropdownButtonHideUnderline(
child: DropdownButton2(
onMenuClose: () {},
onTap: () {},
isExpanded: true,
hint: Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
singlePMSData['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
'₹ ${singlePMSData["current_value"]}',
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
),
items: allPMSListData.map<DropdownMenuItem<Object>>((option) {
return DropdownMenuItem(
value: option,
child: Container(
width: double.infinity,
alignment: Alignment.centerLeft,
// padding: const EdgeInsets.fromLTRB(0,8.0,0,6.0),
child: Row(
children: [
SizedBox(
width: 10,
),
Text(
option["name"],
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
],
),
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: lightGreyColor, width: 1)))),
);
}).toList(),
selectedItemBuilder: (con) {
return allPMSListData.map<Widget>((item) {
return Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
"₹ ${item["current_value"]}",
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
);
}).toList();
},
value: selectedValue,
onChanged: (dynamic value) {
setState(() {
});
},
icon: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
size: 17,
),
),
iconOnClick: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_up,
color: Colors.white,
size: 17,
),
),
iconSize: 14,
buttonHeight: 70,
buttonPadding: const EdgeInsets.only(left: 14, right: 14),
buttonDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: lightBlue,
),
color: Colors.white,
),
buttonElevation: 1,
itemHeight: 44,
itemPadding: const EdgeInsets.only(left: 14, right: 14),
dropdownMaxHeight: 200,
dropdownPadding: null,
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
color: Colors.white,
),
dropdownElevation: 1,
scrollbarRadius: const Radius.circular(40),
scrollbarThickness: 3,
scrollbarAlwaysShow: false,
// offset: const Offset(-10, 0),
),
),
),
);
}
}

How to make Container height dynamic to fit ListView but to certain max height Flutter

I am trying to show ListView in a custom dialog window. What I want to make dialog box height dynamic according to ListView content but to certain max height. If the ListView content reaches specific height it should me scrollable.
This is my code:
class PeekTableDialog extends StatefulWidget {
Order order;
PeekTableDialog({required this.order});
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return PeekTableDialogState();
}
}
class PeekTableDialogState extends State<PeekTableDialog> {
final ScrollController controller = ScrollController();
#override
void dispose() {
controller.dispose();
super.dispose();
}
#override
void initState() {
super.initState();
}
Widget getExtras(Food fooditem) {
List<String> extras = [];
for (var extra in fooditem.extras) {
if (fooditem.extras.last == extra) {
extras.add(extra.name);
} else {
extras.add(extra.name + ', ');
}
}
return Wrap(
runSpacing: 2,
spacing: 2,
children: List.generate(
extras.length,
(index) {
return Text(
extras[index].toString(),
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.normal,
fontStyle: FontStyle.italic,
),
);
},
),
);
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return SizedBox(
width: MediaQuery.of(context).size.width * 0.50,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
color: Colors.grey[400],
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
alignment: Alignment.center,
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.center,
child: Text(
widget.order.table!.name,
style: AppTextStyles().style2,
),
),
),
IconButton(
onPressed: () {
Navigator.of(context).pop();
},
padding: EdgeInsets.zero,
icon: Icon(
Icons.close,
color: Colors.white,
size: 35,
),
),
],
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
alignment: Alignment.center,
child: Text(
'\$' + widget.order.total,
style: TextStyle(
color: Colors.grey[800],
fontSize: 35,
fontWeight: FontWeight.w400,
),
),
),
SizedBox(
height: 15,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Expanded(
child: Text(
'Qty',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(
width: 10,
),
Expanded(
flex: 2,
child: Text(
'Item',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(
width: 10,
),
Expanded(
child: Container(
child: Text(
'Price',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.w700,
),
),
),
),
const SizedBox(
width: 10,
),
Expanded(
child: Container(
child: Text(
'Disc.',
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.w700,
),
),
),
),
],
),
const Divider(
color: Colors.grey,
height: 1.5,
),
const SizedBox(
height: 10,
),
Container(
padding: EdgeInsets.only(bottom: 30),
child: Scrollbar(
isAlwaysShown: true,
controller: controller,
thickness: 12,
showTrackOnHover: true,
child: ListView.separated(
itemCount: widget.order.cartItems.length,
controller: controller,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return Container(
child: Row(
children: [
Expanded(
child: Container(
alignment: Alignment.centerLeft,
child: Text(
widget.order.cartItems[index].cartCount
.toString(),
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
),
),
const SizedBox(
width: 10,
),
Expanded(
flex: 2,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
widget.order.cartItems[index].name,
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
const SizedBox(
height: 5,
),
getExtras(widget.order.cartItems[index]),
],
),
),
),
const SizedBox(
width: 10,
),
Expanded(
child: Container(
alignment: Alignment.centerLeft,
child: Text(
'\$' +
widget.order.cartItems[index].totalPrice
.toStringAsFixed(2),
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
),
),
const SizedBox(
width: 10,
),
Expanded(
child: Container(
alignment: Alignment.centerLeft,
child: Text(
'\$' +
widget
.order.cartItems[index].newDiscPrice
.toStringAsFixed(2),
style: TextStyle(
color: Colors.grey[700],
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
),
),
],
),
);
},
separatorBuilder: (context, index) {
return const SizedBox(height: 3);
},
),
),
),
],
),
),
],
),
);
}
}
Anyone help me please with this small issue.
Thanks in advance.
Well, It's pretty easy. All you have to do is to create a class like this :
class ExpandableText extends StatefulWidget {
ExpandableText(this.text, this.isLongText, {Key? key}) : super(key: key);
final String text;
bool isExpanded = false;
final bool isLongText;
#override
_ExpandableTextState createState() => _ExpandableTextState();
}
class _ExpandableTextState extends State<ExpandableText>
with TickerProviderStateMixin<ExpandableText> {
#override
void initState() {
if (widget.isLongText) {
setState(() {
widget.isExpanded = false;
});
} else {
widget.isExpanded = true;
}
super.initState();
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
AnimatedSize(
vsync: this,
duration: const Duration(milliseconds: 500),
child: ConstrainedBox(
constraints: widget.isExpanded
? const BoxConstraints(maxHeight: 250.0)
: const BoxConstraints(
maxHeight: 60.0,
),
child: SingleChildScrollView(
child: Text(
widget.text,
overflow: TextOverflow.fade,
),
),
),
),
widget.isExpanded
? ConstrainedBox(constraints: const BoxConstraints())
: TextButton(
style: const ButtonStyle(alignment: Alignment.topRight),
child: const Text(
'Expand..'
),
onPressed: () => setState(() => widget.isExpanded = true),
),
],
);
}
}
Just play with the maxHeight according to your needs. Call this class like this (inside your dialog window) :
ExpandableText(
dataToBeShown,
dataToBeShown.length > 250 ? true : false,
),

Context: Found this candidate, but the arguments don't match

I'm new on flutter, I have 2 screens and I have tried a lot to fix the problems and make this code run, the error shows when I tried to push arguments in the constructor to BmiResultScreen
BmiScreen code (which i need to get the values from):
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'bmi_result_screen.dart';
class BmiScreen extends StatefulWidget {
#override
_BmiScreenState createState() => _BmiScreenState();
}
class _BmiScreenState extends State<BmiScreen> {
bool isMale = true;
double height = 120.0;
int age = 0;
double weight = 0.0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BMI Calculator'),
),
body: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(children: [
Expanded(
child: GestureDetector(
onTap: (){
setState(() {
isMale = true;
});
},
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Image(
image: AssetImage('assets/images/male.png'),
height: 90.0,
width: 90.0,
),
SizedBox(
height: 15.0,
),
Text('MALE',
style: TextStyle(
fontSize: 25.0, fontWeight: FontWeight.bold))
],
),
decoration: BoxDecoration(
color: isMale ? Colors.blue : Colors.grey[400],
borderRadius: BorderRadiusDirectional.circular(10.0)),
),
),
),
SizedBox(
width: 20.0,
),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
isMale = false;
});
},
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Image(
image: AssetImage('assets/images/female.png'),
height: 90,
width: 90,
),
SizedBox(
height: 15.0,
),
Text('FEMALE',
style: TextStyle(
fontSize: 25.0, fontWeight: FontWeight.bold))
],
),
decoration: BoxDecoration(
color: !isMale ? Colors.blue : Colors.grey[400],
borderRadius: BorderRadiusDirectional.circular(10.0)),
),
),
),
]),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0
),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadiusDirectional.circular(10.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('HEIGHT',
style:
TextStyle(fontSize: 25.0, fontWeight: FontWeight.bold)),
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${height.round()}',
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.w900,
)
),
SizedBox(
width: 5.0,
),
Text(
'cm',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w900
),
),
],
),
Slider(
value: height,
max: 220.0,
min: 80.0,
onChanged: (value) {
setState(() {
height = value;
});
},
),
],
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadiusDirectional.circular(10.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'WEIGHT',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
)
),
SizedBox(
height: 15.0,
),
Text(
'${weight}',
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.w900,
)
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: () {
setState(() {
if(weight>=0.5){
weight = weight -0.5;
}
});
},
child: Icon(
Icons.remove
),
mini: true,
heroTag: '--weight',
),
FloatingActionButton(
onPressed: () {
setState(() {
weight = weight + 0.5;
});
},
child: Icon(
Icons.add
),
mini: true,
heroTag: '++weight',
),
],
),
],
),
),
),
SizedBox(
width: 20.0,
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadiusDirectional.circular(10.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'AGE',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
)
),
SizedBox(
height: 15.0,
),
Text(
'${age}',
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.w900,
)
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FloatingActionButton(
onPressed: () {
setState(() {
if(age >= 1){
--age;
}
});
},
child: Icon(
Icons.remove
),
mini: true,
heroTag: '--age',
),
FloatingActionButton(
onPressed: () {
setState(() {
++age;
});
},
child: Icon(
Icons.add
),
mini: true,
heroTag: '++age',
),
],
),
],
),
),
),
],
),
),
),
Container(
color: Colors.blue,
width: double.infinity,
height: 50.0,
child: MaterialButton(
onPressed: () {
double result = weight / pow(height/100,2);
print(result.round());
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BmiResultScreen(
isMale: isMale,
age: age,
result: result.round(),
),
)
);
},
child: const Text('CALCULATE'),
),
),
],
),
);
}
}
BmiResultScreen code(which I'm trying to use the values comes from the last screen):
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class BmiResultScreen extends StatelessWidget {
final bool isMale;
final int result;
final int age;
BmiResultScreen({
required this.isMale,
required this.age,
required this.result,
});
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'BMI Result'
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Gender: $isMale',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Result: ${result.round()}',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
Text(
'Age: $age',
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
],
),
)
);
}
}
Problems like this can be fixed by upgrading your flutter version or cleaning.
flutter upgrade --force
flutter clean
delete Podfile and Podfile.lock
run pub get
flutter run

Flutter: Updating UI from outside of a StatefulWidget

I am new to flutter, and working on a shopping cart project. i don't know how exatly i am suppose to ask this question but, here is what i wanted.
I am trying to update my UI when the cart item and prices changes, which means to display sum amount of products from ListView (Stateful widget) to main OrderPage Stateful widget. I know about setState() method, but i think i should use some callback methods here, dont know exactly.
I have explained in short in Image - see below img
What i have done: when user modify cart products, I have saved the value (price/product/count) in to constant value , i calculate the value and save in constant value, and later use that const var in Main widget (Main Ui), which does update when i close and reopen the page, but could not able to update when button pressed (product +/-buttons)
What i want to do is,
Update my total value when +/- buttons are pressed.
Here is my full code:
class cartConstant{
static int packageCount;
static List<int> list;
}
class OrderPage extends StatefulWidget {
#override
_OrderPageState createState() => _OrderPageState();
}
class _OrderPageState extends State<OrderPage> {
int data = 3;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
automaticallyImplyLeading: true,
iconTheme: IconThemeData(
color: Colors.black54, //change your color here
),
backgroundColor: Colors.white,
elevation: 1,
title: Text("Your order Summery",style: TextStyle(color: Colors.black54),),
centerTitle: true,
),
body: Container(
child:
FutureBuilder(
builder: (context, snapshot){
// var datas = snapshot.data;
return
ListView.builder(
physics: ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: data,
itemBuilder: (BuildContext context, int index){
// Cart cart = datas[index];
return CartListView();
},
padding: EdgeInsets.symmetric(horizontal: 10.0),
scrollDirection: Axis.vertical,
);
},
),
),
bottomNavigationBar: _buildTotalContainer(),
);
}
Widget _buildTotalContainer() {
return Container(
height: 220.0,
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
),
child: Column(
children: <Widget>[
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Subtotal",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
cartConstant.packageCount.toString(),
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
),
SizedBox(
height: 15,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Discount",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
"0.0",
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 10.0,
),
Divider(
height: 2.0,
),
SizedBox(
height: 20.0,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Cart Total",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
cartConstant.packageCount.toString(),
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 20.0,
),
GestureDetector(
onTap: () {
// Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => SignInPage()));
},
child: Container(
height: 50.0,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(35.0),
),
child: Center(
child: Text(
"Proceed To Checkout",
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
SizedBox(
height: 20.0,
),
],
),
);
}
}
class CartListView extends StatefulWidget {
#override
_CartListViewState createState() => _CartListViewState();
}
class _CartListViewState extends State<CartListView> {
int _counter = 1;
int getPrice(int i,int priceC){
cartConstant.packageCount = i*priceC;
return cartConstant.packageCount;
}
#override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 15.0),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Color(0xFFD3D3D3), width: 2.0),
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: (){
setState(() {
_counter++;
if (_counter > 20) {
_counter = 20;
}
});
},
child: Icon(Icons.add, color: Color(0xFFD3D3D3))),
Text(
"$_counter",
style: TextStyle(fontSize: 18.0, color: Colors.grey),
),
InkWell(
onTap:(){
setState(() {
_counter--;
if (_counter < 2) {
_counter = 1;
}
});
},
child: Icon(Icons.remove, color: Color(0xFFD3D3D3))),
],
),
),
),
SizedBox(
width: 20.0,
),
Container(
height: 70.0,
width: 70.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/food.jpg"),
fit: BoxFit.cover),
borderRadius: BorderRadius.circular(35.0),
boxShadow: [
BoxShadow(
color: Colors.black54,
blurRadius: 5.0,
offset: Offset(0.0, 2.0))
]),
),
SizedBox(
width: 20.0,
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Employee Package",
style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 5.0),
SizedBox(height: 5.0),
Container(
height: 25.0,
width: 120.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Row(
children: <Widget>[
Text("Price",
style: TextStyle(
color: Color(0xFFD3D3D3),
fontWeight: FontWeight.bold)),
SizedBox(
width: 5.0,
),
InkWell(
onTap: () {},
child: Text(
getPrice(_counter, 2000).toString(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red,
),
),
),
SizedBox(
width: 10.0,
),
],
),
],
),
),
],
),
Spacer(),
GestureDetector(
onTap: () {
},
child: Icon(
Icons.cancel,
color: Colors.grey,
),
),
],
),
),
);
}
}
you can also check from my cart screen shot below:
You can copy paste run full code below
You can use callback refresh() and pass callback to CartListView
code snippet
class _OrderPageState extends State<OrderPage> {
int data = 3;
void refresh() {
setState(() {});
}
...
itemBuilder: (BuildContext context, int index) {
// Cart cart = datas[index];
return CartListView(refresh);
},
...
class CartListView extends StatefulWidget {
VoidCallback callback;
CartListView(this.callback);
...
InkWell(
onTap: () {
setState(() {
_counter++;
if (_counter > 20) {
_counter = 20;
}
});
widget.callback();
},
working demo
full code
import 'package:flutter/material.dart';
class cartConstant {
static int packageCount;
static List<int> list;
}
class OrderPage extends StatefulWidget {
#override
_OrderPageState createState() => _OrderPageState();
}
class _OrderPageState extends State<OrderPage> {
int data = 3;
void refresh() {
setState(() {});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
automaticallyImplyLeading: true,
iconTheme: IconThemeData(
color: Colors.black54, //change your color here
),
backgroundColor: Colors.white,
elevation: 1,
title: Text(
"Your order Summery",
style: TextStyle(color: Colors.black54),
),
centerTitle: true,
),
body: Container(
child: FutureBuilder(
builder: (context, snapshot) {
// var datas = snapshot.data;
return ListView.builder(
physics: ClampingScrollPhysics(),
shrinkWrap: true,
itemCount: data,
itemBuilder: (BuildContext context, int index) {
// Cart cart = datas[index];
return CartListView(refresh);
},
padding: EdgeInsets.symmetric(horizontal: 10.0),
scrollDirection: Axis.vertical,
);
},
),
),
bottomNavigationBar: _buildTotalContainer(),
);
}
Widget _buildTotalContainer() {
return Container(
height: 220.0,
padding: EdgeInsets.only(
left: 10.0,
right: 10.0,
),
child: Column(
children: <Widget>[
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Subtotal",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
cartConstant.packageCount.toString(),
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
),
SizedBox(
height: 15,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Discount",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
"0.0",
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 10.0,
),
Divider(
height: 2.0,
),
SizedBox(
height: 20.0,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Cart Total",
style: TextStyle(
color: Color(0xFF9BA7C6),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
Text(
"8000",
style: TextStyle(
color: Color(0xFF6C6D6D),
fontSize: 16.0,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 20.0,
),
GestureDetector(
onTap: () {
// Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) => SignInPage()));
},
child: Container(
height: 50.0,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(35.0),
),
child: Center(
child: Text(
"Proceed To Checkout",
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
SizedBox(
height: 20.0,
),
],
),
);
}
}
class CartListView extends StatefulWidget {
VoidCallback callback;
CartListView(this.callback);
#override
_CartListViewState createState() => _CartListViewState();
}
class _CartListViewState extends State<CartListView> {
int _counter = 1;
int getPrice(int i, int priceC) {
cartConstant.packageCount = i * priceC;
return cartConstant.packageCount;
}
#override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0, vertical: 15.0),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Color(0xFFD3D3D3), width: 2.0),
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_counter++;
if (_counter > 20) {
_counter = 20;
}
});
widget.callback();
},
child: Icon(Icons.add, color: Color(0xFFD3D3D3))),
Text(
"$_counter",
style: TextStyle(fontSize: 18.0, color: Colors.grey),
),
InkWell(
onTap: () {
setState(() {
_counter--;
if (_counter < 2) {
_counter = 1;
}
});
widget.callback();
},
child: Icon(Icons.remove, color: Color(0xFFD3D3D3))),
],
),
),
),
SizedBox(
width: 20.0,
),
Container(
height: 70.0,
width: 70.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/food.jpg"),
fit: BoxFit.cover),
borderRadius: BorderRadius.circular(35.0),
boxShadow: [
BoxShadow(
color: Colors.black54,
blurRadius: 5.0,
offset: Offset(0.0, 2.0))
]),
),
SizedBox(
width: 20.0,
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Employee Package",
style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
),
SizedBox(height: 5.0),
SizedBox(height: 5.0),
Container(
height: 25.0,
width: 120.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Row(
children: <Widget>[
Text("Price",
style: TextStyle(
color: Color(0xFFD3D3D3),
fontWeight: FontWeight.bold)),
SizedBox(
width: 5.0,
),
InkWell(
onTap: () {},
child: Text(
getPrice(_counter, 2000).toString(),
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red,
),
),
),
SizedBox(
width: 10.0,
),
],
),
],
),
),
],
),
Spacer(),
GestureDetector(
onTap: () {},
child: Icon(
Icons.cancel,
color: Colors.grey,
),
),
],
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: OrderPage(),
);
}
}
When the button is tapped, you just need to update the Subtotal amount and cart total.
Step 1 : Replace the harcoded value by a variable. So, something like :
Row(
children: <Widget>[
Text(
"Subtotal",
style: ...
),
Text(
"$subTotal",
style: ....
),
],
),
Step 2 : Now, add a code to calcualte subTotal and cartTotal. You already have code which increments and decrements the variable _counter. You just need to tweak that part like :
setState( (){
_counter++;
// So, the quantity is increased. Just get the price of current item and add in the sub total.
subTotal += priceC;
cartTotal = subTotal - discount;
} );