Flutter The error I received when firebase listing - flutter

I've been investigating a problem for days.
This is how I use Firebase Database.
My goal is to list the contents of the firebase database.
but every time I try, I get an error.
-urunler
-elyapimi
--LB445dadwSDA5
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
--LbVuRaL2eslQ4deD-C7
ad: "deneme"
fiyat: "110"
imageurl: "https://firebasestorage.googleapis.com/v0/b/ben..."
infiyat: "85.55"
I want to list the contents of the database.
but I get this error.
E/flutter ( 9624): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled
Exception: type 'double' is not a subtype of type 'String'
E/OpenGLRenderer( 9624): SFEffectCache:clear(), mSize = 0
W/ManagedEGLContext( 9624): doTerminate failed: EGL count is 2 but
managed count is 1
these are the codes I use
import 'package:denemeflutter/database.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
class YenilenCicek extends StatefulWidget{
#override
State<StatefulWidget> createState() => YenilenCicekState();
}
class YenilenCicekState extends State with TickerProviderStateMixin{
static const EndColor = Color.fromARGB(255, 150, 202, 230);
static const StartColor = Color.fromARGB(255, 64, 222, 194);
static const softmavi = Color.fromARGB(255, 142, 226, 210);
List<MyDatabase> list = [];
#override
void initState() {
super.initState();
DatabaseReference postRef =
FirebaseDatabase.instance.reference().child("urunler").child("elyapimi");
postRef.once().then((DataSnapshot snap)
{
var keys = snap.value.keys;
var data = snap.value;
list.clear();
for(var key in keys)
{
MyDatabase myDatabase = new MyDatabase
(
data[key]["ad"],
data[key]["imageurl"],
data[key]["infiyat"],
data[key]["fiyat"]);
list.add(myDatabase);
}
setState(() {
print("Lenght : $list.lenght");
});
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
height: 100,
width: double.maxFinite,
color: Colors.white,
),
Positioned(
child:Container(
padding: EdgeInsets.only(left: 170, top: 30),
height: 100.0,
decoration: BoxDecoration(
gradient: new LinearGradient(colors: [StartColor,EndColor]),
borderRadius: BorderRadius.only(bottomLeft:
Radius.elliptical(300, 10) , bottomRight: Radius.elliptical(300, 10)
) ,
),
child: null,
),
),
Positioned(
child: Container(
padding: EdgeInsets.only(top: 35, left: 0),
child: FlatButton(
padding: EdgeInsets.only(left: 0,right: 25),
onPressed: (){Navigator.pop(context);},
child: Icon(Icons.keyboard_arrow_left,color:
Colors.white,size: 50,)
),
),
),
Positioned(
child: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(bottom: 525),
child: Text("YENİLEN ÇİÇEKLER", style: TextStyle(color:
Colors.white, fontSize: 19),),
)
),
Container(
margin: EdgeInsets.only(top: 130),
child: list.length == 0 ? new Text("Bu Kategoride\nÜrün
Bulunmamaktadır.", textAlign: TextAlign.center,) : new
ListView.builder(
itemCount: list.length,
itemBuilder: (_,index){
return ListUI(list[index].title, list[index].imageurl,
list[index].promoprice, list[index].price);
},
),
)
],
),
);
}
Widget ListUI(String ad,String imageurl,String infiyat,String fiyat,)
{
return new Card(
elevation: 10.0,
margin: EdgeInsets.all(15.0),
child: new Container(
padding: new EdgeInsets.all(14.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Image.network("$imageurl"),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("$ad", style: TextStyle(color: Color.fromARGB(255, 64,
222, 194), fontSize: 18, ),textAlign: TextAlign.center,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("$infiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
Text("$fiyat", style: TextStyle(color:
Color.fromARGB(255, 64, 222, 194), fontSize: 18),),
],
)
],
),
],
),
),
);
}
}
I Thanks in advance to friends who can help.

In your MyDatabase class, you have infiyat as type String, but it is comming in as a double i.e "85.55". Either change the type in your database or your class.

Related

i cant update itemcount

hey why is my itemcount not working i have 6 rows in my database but when i run the code it show me only one row and the other rows not showing it
this is my code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class my_ads extends StatefulWidget {
const my_ads({Key? key}) : super(key: key);
#override
State<my_ads> createState() => _my_adsState();
}
List list = [];
int select_item = 0;
class _my_adsState extends State<my_ads> {
#override
Future ReadData() async {
var url = "https://***.***.***.**/getData.php";
var res = await http.get(Uri.parse(url));
if (res.statusCode == 200) {
var red = jsonDecode(res.body);
setState(() {
list.addAll(red);
});
print(list);
}
}
#override
void initState() {
super.initState();
GetData();
}
GetData() async {
await ReadData();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: list.length,
itemBuilder: ((cts, i) {
return Container(
height: 800,
child: ListView(
children: [
Container(
margin: EdgeInsets.only(left: 70, right: 60),
height: 54.0,
width: 224.0,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xffF4AC47), width: 5),
color: Color(0xff42A9D2),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(40),
bottomRight: Radius.circular(40))),
child: new Center(
child: new Text(
"MyAds",
style: TextStyle(
fontSize: 25,
color: Color(0xff072A52),
fontFamily: 'Cairo'),
textAlign: TextAlign.center,
),
//end logo
)),
),
///start Section
Container(
margin: EdgeInsets.only(left: 10, right: 10, top: 10),
height: 180.0,
width: 430.0,
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color(0xff42A9D2), width: 5),
borderRadius: BorderRadius.circular(8)),
child: new Container(
child: Row(
children: [
Expanded(
child: Image(
image: AssetImage("assets/book.jpg"),
)),
Container(
margin: EdgeInsets.only(
left: 110, top: 30, right: 13),
child: Column(
children: [
Text(
"test",
style: TextStyle(
fontSize: 20, color: Colors.black87),
),
SizedBox(
height: 20,
),
Row(
children: [
Text("test2"),
Icon(Icons.perm_identity_rounded)
],
),
SizedBox(
height: 5,
),
Row(
children: [
Text("}"),
Column(
children: [Icon(Icons.store)],
)
],
),
],
),
)
],
)
//end logo
)),
),
],
),
);
})));
}
}
i tried to change ListView to ListTile but the design will be detroyed becuse i need to make the same design to other pages but my problem is with itemcount its not making any changes ! please if you have any ideas with my problem give me ansewrs

Tutorial Coach Mark package flutter - Opacity not showing, screen flashing and skipping not working

I am trying to use the Tutorial Coach Mark package to make the tutorial screen for my app. Though I have 3 problems:
the opacity of the screen color is not working
the text of the tutorial under the highlighted target keeps flashing
skip function is not working when clicking
I have followed each step of this tutorial
https://www.youtube.com/watch?v=nBdPl6jjsoU
but it is not working.
Here is my code. The related part is in the MusicScreen class.
final List<String> Url_list = [
// testa:
'https://www.youtube.com/watch?v=38rQO3dMZrc',
// third eye:
'https://www.youtube.com/watch?v=s2ddLEfSEIA',
//gola
'https://www.youtube.com/watch?v=QJs4iCV-g6I',
// cuore
'https://www.youtube.com/watch?v=q1Ng7FgDsNQ'
// addome
'https://www.youtube.com/watch?v=8s8R8vR53n4',
// sacral
'https://www.youtube.com/watch?v=ueV0WPUUAj0',
// root
'https://www.youtube.com/watch?v=OMPaU5L3zy0'
];
Future<void> _launchURL(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: false,
);
} else {
throw 'Could not launch $url';
}
print('cant launch ulr');
}
class MusicScreen extends StatefulWidget {
static const routeName = '/music-screen';
#override
_MusicScreenState createState() => _MusicScreenState();
}
class _MusicScreenState extends State<MusicScreen> {
final user = FirebaseAuth.instance.currentUser!;
bool isHover = false;
TutorialCoachMark? tutorialCoachMark;
List<TargetFocus> targets = [];
GlobalKey key1 = GlobalKey();
#override
void initState() {
initTarget();
WidgetsBinding.instance.addTimingsCallback(_afterLayout);
super.initState();
}
void _afterLayout(_) {
Future.delayed(Duration(milliseconds: 100));
showTutorial();
}
void showTutorial() {
tutorialCoachMark = TutorialCoachMark(
textSkip: 'SKIP TUTORIAL',
paddingFocus: 10,
opacityShadow: 0.8,
targets: targets,
)..show(context: context);
}
void initTarget() {
targets.add(
TargetFocus(
color: AppColors.darkPink,
identify: 'target 0',
keyTarget: key1,
contents: [
TargetContent(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 5,
),
Text(
'Tap any of the Chakra to get your music',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.white),
),
],
),
),
),
],
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
endDrawer: MainDrawer(
onTap: () {},
),
backgroundColor: AppColors.lightPink,
appBar: AppBar(
shadowColor: AppColors.lightPink,
backgroundColor: AppColors.midPink,
title: Text(
'MUSICENERGY',
style: Theme.of(context).appBarTheme.textTheme!.headline6,
),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Stack(
children: [
Container(
padding: EdgeInsets.only(top: 70),
child: Image.asset('images/Meditation.png'),
),
Positioned(
top: -55,
left: 95,
child: Container(
padding: EdgeInsets.all(10),
height: 200,
width: 200,
child: Image.asset('images/testa.png'),
),
),
Positioned(
key: key1,
top: 30,
left: 172,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[0]);
},
),
),
Positioned(
top: 30,
left: 90,
child: Container(
padding: EdgeInsets.all(10),
height: 200,
width: 200,
child: Image.asset('images/occhio.png'),
),
),
Positioned(
top: 115,
left: 174,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[1]);
},
),
),
Positioned(
top: 110,
left: 105,
child: Container(
padding: EdgeInsets.all(10),
height: 200,
width: 200,
child: Image.asset('images/gola.png'),
),
),
Positioned(
top: 195,
left: 177,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[2]);
},
),
),
Positioned(
top: 180,
left: 90,
child: Container(
padding: EdgeInsets.all(30),
height: 200,
width: 200,
child: Image.asset('images/cuore.png'),
),
),
Positioned(
top: 265,
left: 178,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[3]);
},
),
),
Positioned(
top: 220,
left: 50,
child: Container(
padding: EdgeInsets.all(30),
height: 250,
width: 250,
child: Image.asset('images/addome.png'),
),
),
Positioned(
top: 330,
left: 177,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[4]);
},
),
),
Positioned(
top: 317,
left: 103,
child: Container(
padding: EdgeInsets.all(15),
height: 200,
width: 200,
child: Image.asset('images/sacro.png'),
),
),
Positioned(
top: 402,
left: 177,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[5]);
},
),
),
Positioned(
top: 385,
left: 109,
child: Container(
padding: EdgeInsets.all(15),
height: 200,
width: 200,
child: Image.asset('images/root.png'),
),
),
Positioned(
top: 470,
left: 178,
child: PulsatingCircleIconButton(
() {
_launchURL(Url_list[6]);
},
),
),
],
),
),
],
),
);
}
// refresh() {
// setState(() {});
}
class MainDrawer extends StatelessWidget {
final FirebaseServices _auth = FirebaseServices();
final user = FirebaseAuth.instance.currentUser!;
final Function()? onTap;
MainDrawer({required this.onTap});
#override
Widget build(BuildContext context) {
return Drawer(
child: Column(
children: [
Container(
height: 95,
width: double.infinity,
padding: EdgeInsets.all(25),
color: AppColors.darkPink,
alignment: Alignment.centerLeft,
child: Row(children: [
CircleAvatar(
radius: 25,
backgroundImage: NetworkImage(user.photoURL!),
),
SizedBox(
width: 12,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
user.displayName!,
style: (TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.black)),
),
Text(
user.email!,
),
],
),
]),
),
SizedBox(
height: 10,
),
ListTile(
leading: Icon(Icons.star),
title: Text(
'Favourites',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
onTap: onTap,
),
ListTile(
leading: Icon(
Icons.exit_to_app,
),
title: Text(
'Log Out',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
onTap: () {
Navigator.pushNamed(context, AuthScreen.routeName);
_auth.signOut();
},
),
],
),
);
}
}
class PulsatingCircleIconButton extends StatefulWidget {
final GestureTapCallback onTap;
PulsatingCircleIconButton(this.onTap);
#override
_PulsatingCircleIconButtonState createState() =>
_PulsatingCircleIconButtonState();
}
class _PulsatingCircleIconButtonState extends State<PulsatingCircleIconButton>
with SingleTickerProviderStateMixin {
AnimationController? _animationController;
Animation? _animation;
#override
void initState() {
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_animation = Tween(begin: 0.0, end: 12.0).animate(
CurvedAnimation(parent: _animationController!, curve: Curves.easeOut));
_animationController!.repeat(reverse: true);
super.initState();
}
#override
Widget build(BuildContext context) {
return InkWell(
radius: 100,
borderRadius: BorderRadius.circular(50),
onTap: widget.onTap,
splashColor: AppColors.Violet,
child: AnimatedBuilder(
animation: _animation!,
builder: (context, _) {
return Ink(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.midBlue,
shape: BoxShape.circle,
boxShadow: [
for (int i = 1; i <= 2; i++)
BoxShadow(
color: AppColors.lightBlue
.withOpacity(_animationController!.value / 2),
spreadRadius: _animation!.value * i,
),
],
),
);
},
),
);
}
}
Also I am embedding two pictures showing the problem related to the flashing text. It keeps going from solid white to a greyed out white.
enter image description here
enter image description here
I would really appreciate if anyone could help me on this. I have tried literally everything but I can't find where the problem is.
Thanks in advance.

geting data from firebase in flutter

im trying to get data from firebase
the main page show the data correctly based on the length
but the details page is not the data of the first index is duplicated to the on the other pages
this is the main page and it shows different data correctly
but the first details page keep duplicate it self
this is the detail page code
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:online_shop/api/summer_list_api.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';
import 'package:online_shop/pages/home_page.dart';
import 'package:online_shop/view/widgets/costum_button.dart';
import 'package:online_shop/view/widgets/costum_text.dart';
import 'package:online_shop/view/widgets/nav.dart';
import 'package:provider/provider.dart';
class DetalsPage extends StatefulWidget {
DetalsPage({Key? key}) : super(key: key);
#override
_DetalsPage createState() => _DetalsPage();
}
class _DetalsPage extends State<DetalsPage> {
late Future Summers;
#override
void initState() {
Summers = getsummerinfo(SummerNotifier());
super.initState();
}
#override
Widget build(BuildContext context) {
SummerNotifier summerNotifier = Provider.of<SummerNotifier>(context);
return Scaffold(
body: ListView.builder(
itemCount: 1,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Column(
children: [
Container(
child: Stack(
children: [
Image.network(
summerNotifier.summerList[index].Imag,
width: 400,
fit: BoxFit.fitWidth,
),
Container(
margin: const EdgeInsets.only(top: 40, left: 5),
child: IconButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) {
return Nav();
}));
},
icon: Icon(Icons.arrow_back_ios))),
Container(
height: 575,
margin: const EdgeInsets.only(top: 230),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20)),
child: Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: ListView.builder(
itemCount: 1,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 10,
),
child: CoustumText(
text: summerNotifier.summerList[index].name,
size: 30,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(
left: 10, right: 10),
child: CoustumText(
text: summerNotifier
.summerList[index].sub_info,
size: 16,
color: Colors.black,
),
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.only(left: 10),
child: CoustumText(
text: "some of the place photos:",
size: 18,
color: Colors.black,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
FutureBuilder(
future: Summers,
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text("there is issu ");
case ConnectionState.waiting:
return CircularProgressIndicator();
default:
if (snapshot.hasError) {
return Text("Error");
}
}
return CarouselSlider(
items: summerNotifier
.summerList[index].sub_img
?.map((items) => Container(
height: 200,
child: Image.network(
items,
fit: BoxFit.cover,
),
))
.toList(),
options:
CarouselOptions(autoPlay: false),
);
}),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(left: 10),
child: CoustumText(
text: "trip informations:",
size: 20,
color: Colors.black,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(
left: 10, right: 10),
child: Container(
child: CoustumText(
text:
"The trip is for 7 days and 8 nights and ther will be a program for spinding the time,every day ther will be a new place to discover so relax and lets the journy start.",
size: 16,
color: Colors.black,
),
),
),
const SizedBox(
height: 20,
),
Container(
child: Padding(
padding: const EdgeInsets.only(
left: 10, right: 10),
child: Column(
children: [
CoustumText(
text: "Contact informations:",
size: 20,
color: Colors.black,
fontWeight: FontWeight.w600,
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
children: const [
Icon(
Icons.phone,
size: 20,
),
SizedBox(
width: 5,
),
CoustumText(
text: "85746385",
size: 16,
color: Colors.black),
],
),
Row(
children: const [
Icon(
Icons.facebook_rounded,
color: Colors.blueAccent,
size: 30,
),
SizedBox(
width: 5,
),
CoustumText(
text: "Flay_fun",
size: 16,
color: Colors.black),
],
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Row(
children: const [
Icon(
Icons.phone,
size: 20,
),
SizedBox(
width: 5,
),
CoustumText(
text: "85208579",
size: 16,
color: Colors.black),
],
),
Row(
children: const [
Icon(
Icons.email_rounded,
color: Colors.blueAccent,
size: 30,
),
SizedBox(
width: 5,
),
CoustumText(
text: "Flayfun#gmail.com",
size: 16,
color: Colors.black),
],
),
],
),
],
),
),
),
const SizedBox(
height: 20,
),
Container(
width: 200,
child: CoustumButton(
text: "book now \$200",
onPressed: () {},
size: 20,
),
),
],
);
},
),
),
),
],
),
),
],
);
},
),
);
}
}
this is the method to get the data
// ignore_for_file: unused_local_variable, non_constant_identifier_names
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';
Future getsummerinfo (SummerNotifier summerNotifier) async {
QuerySnapshot snapshot =
await FirebaseFirestore.instance.collection("Summer_D").get();
List<Summer_d> _summerList = [];
snapshot.docs.forEach((docs) {
Summer_d summer_d = Summer_d.fromMap(docs.data() as Map<String, dynamic>);
_summerList.add(summer_d);
});
summerNotifier.summerList = _summerList;
}
this is the other one
// ignore_for_file: unused_local_variable, non_constant_identifier_names
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:online_shop/core/services/summer_notifier.dart';
import 'package:online_shop/model/Summer_d_model.dart';
Future getsummerinfo (SummerNotifier summerNotifier) async {
QuerySnapshot snapshot =
await FirebaseFirestore.instance.collection("Summer_D").get();
List<Summer_d> _summerList = [];
snapshot.docs.forEach((docs) {
Summer_d summer_d = Summer_d.fromMap(docs.data() as Map<String, dynamic>);
_summerList.add(summer_d);
});
summerNotifier.summerList = _summerList;
}
this is the models
// ignore_for_file: camel_case_types
class Summer_d {
late String Imag;
late String info;
late String name;
late int price;
late String sub_info;
late List<dynamic>? sub_img;
Summer_d.fromMap(Map<String,dynamic>data){
Imag = data["Imag"];
info = data ["info"];
name = data ["name"];
price = data["price"];
sub_info = data ["sub_info"];
sub_img = data ["sub_img"];
}
}
You're hardcoding the itemCount in the ListView.builder, and then in the ListView.builder, in its itemBuilder method, you're saying summerNotifier.summerList[index]. The index will always be zero.
#override
Widget build(BuildContext context) {
SummerNotifier summerNotifier = Provider.of<SummerNotifier>(context);
return Scaffold(
body: ListView.builder(
itemCount: 1, // hard-coding this to 1
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
// here the index will always be zero,
// since above you specified itemCount = 1
summerNotifier.summerList[index]
}
)
);
}
I'd actually use the SummerNotifier service you have to hold on to the selected item reference and then in the Details page I get it from the service and populate the details of that item. Or in your case, the index of the selected item.
I believe that's your issue.

how to make this table scrollable to bottom

i am beginner in flutter , i wrote a code with a leagueboard table from api , after i executed i found that my table is not scrolling , the scroll appears only on the top but no scrolling to bottom
here what i have tried:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:http/http.dart' as http;
class LeagueBoard extends StatefulWidget {
#override
_LeagueBoardState createState() => _LeagueBoardState();
}
class _LeagueBoardState extends State<LeagueBoard> {
List<Club> clubs = [];
getTable() async {
http.Response response = await http.get(
'http://api.football-data.org/v2/competitions/PL/standings',
headers: {'X-Auth-Token': '86014f6025ae430dba078acc94bb2647'});
String body = response.body;
Map data = jsonDecode(body);
List table = data['standings'][0]['table'];
// for (var team in table) {
// clubs.add(Club(team['team']['crestUrl'].toString(), team['position'].toString(),team['points'].toString(),team['points'].toString(),team['playedGames'].toString(),team['won'].toString(),
// team['draw'].toString(),team['lost'].toString(),team['goalsFor'],team['goalsAgainst']));
// print(team);
// }
// for (var team in table) {
// clubs.add(Club(team['team']['crestUrl'].toString(), team['position'].toString(),team['points'].toString(),team['points'].toString(),team['playedGames'].toString(),team['won'].toString(),
// team['draw'].toString(),team['lost'].toString(),team['goalsFor'],team['goalsAgainst']));
// print(team);
// }
// for (var team in clubs) {
// debugPrint(team.toString());
// }
setState(() {
for (var team in table) {
clubs.add(Club(team['team']['name'],team['team']['crestUrl'], team['position'].toString(),team['points'].toString(),team['playedGames'].toString(),team['won'].toString(),
team['draw'].toString(),team['lost'].toString(),team['goalsFor'],team['goalsAgainst']));
print("hello");
}
});
}
// List<Club> clubs = [ Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),
// Club("Manchester City","https://upload.wikimedia.org/wikipedia/fr/thumb/b/ba/Logo_Manchester_City_2016.svg/1200px-Logo_Manchester_City_2016.svg.png","1","77","17","15","1","1",25,5),
// Club("Chelsea","https://upload.wikimedia.org/wikipedia/fr/thumb/5/51/Logo_Chelsea.svg/768px-Logo_Chelsea.svg.png","2","70","17","13","2","3",19,8),];
#override
void initState() {
super.initState();
getTable();
}
#override
Widget build(BuildContext context) {
return clubs == null
? Container(
color: Colors.white,
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Color(0xFFe70066),
),
),
),
)
: Scaffold(
appBar: AppBar(
title: Text("LeagueBoard"),
backgroundColor: Colors.blue[300],
elevation: 0.0,
),
body: SingleChildScrollView(
child: Column(
children: [
TopRow(),
ListView.builder(
shrinkWrap: true,
// physics: NeverScrollableScrollPhysics(),
itemCount: clubs.length,
itemBuilder: (context, index) {
return TableRow(index: index, clubs:clubs);
},
),
],
),
),
);
}
}
class TopRow extends StatelessWidget {
const TopRow({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
TextStyle textStyle = TextStyle(fontSize: 11, fontWeight: FontWeight.bold);
TextStyle textStyle2 = TextStyle(fontSize: 13);
return Container(
child: Row(
children: [
Container(
alignment: Alignment.center,
width: 30,
height: 30,
child: Text('#'),
),
SizedBox(width: 20),
Container(alignment: Alignment.center, child: Text('Team')),
Spacer(),
Container(
width: 28,
child: Text('MP', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text('W', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text('D', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text('L', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text('GD', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text('Pts', style: textStyle),
),
SizedBox(
width: 5,
),
Container(
width: 5,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.grey[800],
),
padding: EdgeInsets.fromLTRB(10, 5, 2, 5),
),
],
),
);
}
}
class TableRow extends StatelessWidget {
final int index;
final List<Club> clubs;
const TableRow({
this.index,
this.clubs,
Key key,
}) : super(key: key);
/////////////////////////////////////////////////////////////////////linkwell
////////////////////////////////////////////////////////////////////
#override
Widget build(BuildContext context) {
TextStyle textStyle = TextStyle(fontSize: 11, fontWeight: FontWeight.bold);
TextStyle textStyle2 = TextStyle(fontSize: 13, fontWeight: FontWeight.bold);
return Container(
width: double.infinity,
height: 40,
decoration: BoxDecoration(
border: Border.all(color: Colors.black38, width: 0.2),
color: index == 0 ? Colors.yellow[100] : Colors.purpleAccent[20],
),
child: Row(
children: [
Container(//iinkwell
alignment: Alignment.center,
width: 30,
height: 40,
color: index < 2
? Colors.blue
: index == 2
? Colors.red[400]
: index > 11
? Colors.red[800]
: Colors.grey[700],
child: Text(
(index + 1).toString(),
style: TextStyle(color: Colors.white),
),
),
SizedBox(width: 20),
Row(children: [
SvgPicture.network(clubs[index].image,
width: 24.0, height: 24.0,
),
SizedBox(width: 5.0),
clubs[index].name.length > 11
? Text(clubs[index].name
.toString()
.substring(0, 11) +
'...')
: Text(clubs[index].name.toString(), style: textStyle2),
],),
Spacer(),
Container(
width: 28,
child: Text(clubs[index].matches, style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text(clubs[index].wins, style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text(clubs[index].draws, style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text(clubs[index].loss, style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text((clubs[index].goals - clubs[index].goalsIn).toString(), style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 28,
child: Text(clubs[index].points, style: textStyle2),
),
SizedBox(
width: 5,
),
Container(
width: 5,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.grey[600],
),
padding: EdgeInsets.fromLTRB(10, 5, 2, 5),
),
],
),
);
}
}
class Club {
String name;
String image;
String rank;
String points;
String matches;
String wins;
String loss;
String draws;
int goals;
int goalsIn;
Club(this.name,this.image,this.rank,this.points, this.matches,this.wins,this.loss,this.draws,this.goals,this.goalsIn);
}
I am trying to make my table scrolling because i can not see all of the teams that came from becand due to non scrolling reasons
You are using ListView inside SingleChildScrollView. So set that ListView as non-primary.
primary: false
Change at this point in your code
ListView.builder(
shrinkWrap: true,
primary: false,
// physics: NeverScrollableScrollPhysics(),
itemCount: clubs.length,
itemBuilder: (context, index) {
return TableRow(index: index, clubs:clubs);
},
),

trying to add to bag and to update prices and cups

I am trying to do this test TODOs: but i have been have issuses pls help: i am trying to Uncomment the _confirmOrderModalBottomSheet() method to show summary of order, Uncomment the setState() function to clear the price and cups, and Change the 'price' to 0 when this button is clicked Increment the _cupsCounter when 'Add to Bag' button is clicked, and to Call setState((){}) method to update both price and cups counter when 'Add to Bag' button is clicked
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Coffee Test',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.white,
),
home: MyHomePage(title: 'Coffee Test'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedPosition = -1;
String _coffeePrice ="0";
int _cupsCounter =0;
int price = 0;
String _currency ="₦";
static const String coffeeCup ="images/coffee_cup_size.png";
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
title: FlatButton(
onPressed: (){
//TODO: Uncomment the _confirmOrderModalBottomSheet() method to show summary of order
//_confirmOrderModalBottomSheet(totalPrice: "$_currency$price", numOfCups: "x $_cupsCounter");
},
child: Text("Buy Now",style: TextStyle(color: Colors.black87),),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18.0), side: BorderSide(color: Colors.blue))
),
actions: [
InkWell(
onTap: () {
//TODO: Uncomment the setState() function to clear the price and cups
//TODO: Change the 'price' to 0 when this button is clicked
setState(() {
this.price = -1;
this._cupsCounter = 0;
});
Icon(Icons.clear);
}),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
height: double.maxFinite,
alignment: Alignment.center,
child: Text("$_cupsCounter Cups = $_currency$price.00", style: TextStyle(fontSize: 18),),
),
)
],
),
body: Padding(padding: EdgeInsets.all(20), child: _mainBody(),) // This trailing comma makes auto-formatting nicer for build methods.
);
}
Widget _mainBody(){
return SingleChildScrollView(
child: Container(
height: double.maxFinite,
width: double.maxFinite,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 0,
child: Stack(
children: [
Container(
width: double.maxFinite,
height: 250,
margin: EdgeInsets.only(left: 50, right: 50, bottom: 50, top: 60),
decoration: BoxDecoration(borderRadius:
BorderRadius.all(Radius.circular(180)),
color: Color.fromRGBO(239, 235, 233, 100)),
),
Container(
alignment: Alignment.center,
width: double.maxFinite,
height: 350,
child: Image.asset("images/cup_of_coffee.png", height: 300,),
)
],
)),
Padding(padding: EdgeInsets.all(10),),
Expanded(flex: 0,child: Text("Caffè Americano",
style: TextStyle(fontWeight: FontWeight.bold,
fontSize: 30),)),
Padding(padding: EdgeInsets.all(6),),
Expanded(flex: 0, child: Text("Select the cup size you want and we will deliver it to you in less than 48hours",
style: TextStyle(fontWeight: FontWeight.bold,
fontSize: 14, color: Colors.black45,),
textAlign: TextAlign.start,),
),
Container(
margin: EdgeInsets.only(top: 30, left: 20),
height: 55,
width: double.maxFinite,
alignment: Alignment.center,
child:Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RichText(text: TextSpan(
text: _currency,
style: TextStyle(fontWeight: FontWeight.bold,
fontSize: 25, color: Colors.black87),
children: [
TextSpan(text: _coffeePrice, style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold))
]
),),
Padding(
padding: EdgeInsets.only(right: 15),
),
ListView.builder(itemBuilder: (context, index){
return InkWell(
child: _coffeeSizeButton(_selectedPosition == index,
index ==0? "S" : index ==1? "M": "L"),
onTap: (){
setState(() {
this._coffeePrice= index ==0? "300" : index ==1? "600": "900";
_selectedPosition = index;
});
},
);
}, scrollDirection: Axis.horizontal,
itemCount: 3, shrinkWrap: true,),
],),
),
Container(
margin: EdgeInsets.only(top: 30),
padding: EdgeInsets.all(10),
width: double.maxFinite,
height: 70,
child: FlatButton(onPressed: (){
//TODO: Currently _cupsCounter only show 1 when this button is clicked.
// TODO: Increment the _cupsCounter when 'Add to Bag' button is clicked'
//TODO: Call setState((){}) method to update both price and cups counter when 'Add to Bag' button is clicked
this._cupsCounter = 1;
this.price += int.parse(_coffeePrice);
}, child: Center(child: Text("Add to Bag",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),)
,),
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
),
),
)
],
),
),
);
}
Widget _coffeeSizeButton(bool isSelected, String coffeeSize){
return Stack(
children: [
Container(alignment: Alignment.center, width: 55,
child: Text(coffeeSize, style: TextStyle(fontSize: 10, fontWeight: FontWeight.bold,
color: isSelected? Colors.blue: Colors.black45),),),
new Container(
margin: EdgeInsets.only(right: 10),
child: Image.asset(coffeeCup, width:50, color: isSelected ? Colors.blue: Colors.black45,),
decoration: BoxDecoration(border: Border(top: BorderSide(color: isSelected? Colors.blue: Colors.black45,
width: isSelected? 2: 1), left: BorderSide(color: isSelected? Colors.blue: Colors.black45,
width: isSelected? 2: 1), bottom: BorderSide(color: isSelected? Colors.blue: Colors.black45,
width: isSelected? 2: 1), right: BorderSide(color: isSelected ?Colors.blue: Colors.black45 ,
width: isSelected? 2: 1)), borderRadius: BorderRadius.all(Radius.circular(5))),
)
],
);
}
void _confirmOrderModalBottomSheet({String totalPrice, String numOfCups}){
showModalBottomSheet(
context: context,
builder: (builder){
return new Container(
height: 150.0,
color: Colors.transparent, //could change this to Color(0xFF737373),
//so you don't have to change MaterialApp canvasColor
child: new Container(
padding: EdgeInsets.all(10),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: Column(
children: [
Container(
child: Text("Confirm Order",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),),
alignment: Alignment.center, height: 30, decoration: BoxDecoration(
), ),
_getEstimate(totalPrice, numOfCups)
],
)),
);
}
);
}
Widget _getEstimate(String totalPrice, String numOfCups){
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Image.asset("images/cup_of_coffee.png", height: 70, width: 50,),
Padding(padding: EdgeInsets.all(10)),
Text(numOfCups, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),),
Padding(padding: EdgeInsets.all(10)),
Text(totalPrice, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),)
],
);
}
}
You're setting 1 to your _cupsCounter instead of adding one to it.
When updating your values, putting the operation i.e _cupsCounter += 1; in setState will update the state of your widget which makes values change in your widgets.
setState((){
_cupsCounter += 1; // make it +=1 instead of =1.
price += int.parse(_coffeePrice);
});
Also you can use setState by putting it after your operation which will update the state of your widget after the operation is done.
_cupsCounter += 1; // make it +=1 instead of =1.
price += int.parse(_coffeePrice);
setState((){});
Full code should look like this.
Container(
margin: EdgeInsets.only(top: 30),
padding: EdgeInsets.all(10),
width: double.maxFinite,
height: 70,
child: FlatButton(onPressed: (){
// Currently _cupsCounter only show 1 when this button is clicked.
// Increment the _cupsCounter when 'Add to Bag' button is clicked'
// Call setState((){}) method to update both price and cups counter when 'Add to Bag' button is clicked
setState((){
_cupsCounter += 1; // make it +=1 instead of =1.
price += int.parse(_coffeePrice);
}); // call setState like this
}, child: Center(child: Text("Add to Bag",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white),)
,),
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50)
),
),
)