Why does my application close when I use a listview with Cards and NetworkImage? - flutter

The ListView.builder is being built with some cards that contain NetworkImage, for the moment it creates 25 cards for me, therefore it has to load 25 images, at the moment of making a slide the application remains stopped and at the end it closes, which could be doing wrong? Here is the code, I would appreciate if you could help me. Images are stored in Firebase Storage and weigh less than 300 kb,
It is also worth mentioning that when I scroll through the listview the images are reloaded.
FutureBuilder(
future: urlPublicaciones.cargarUrlPublicaciones(),
builder: (BuildContext context,
AsyncSnapshot<List<UrlPublicacionesModel>> snapshotUrl) {
if (snapshotUrl.hasData) {
urlPosts = snapshotUrl.data;
return FutureBuilder(
future: urlPublicaciones.cargarPublicaciones(urlPosts),
builder: (BuildContext context,
AsyncSnapshot<List<CategoriasResponse>> snapshot) {
if (snapshot.hasData) {
publicaciones = snapshot.data;
if (publicaciones.isNotEmpty) {
return ListView.builder(
itemCount: publicaciones.length,
itemBuilder: (BuildContext context, int index) {
return Dismissible(
confirmDismiss: (direction) async {
switch (direction) {
case DismissDirection.endToStart:
return await _showConfirmationDialog(
context) ==
true;
case DismissDirection.startToEnd:
return await _showConfirmationDialog(
context) ==
true;
case DismissDirection.horizontal:
case DismissDirection.vertical:
case DismissDirection.up:
case DismissDirection.down:
assert(false);
}
return false;
},
background: Container(
padding:
EdgeInsets.symmetric(horizontal: 12.0),
color: Colors.red,
alignment: Alignment.centerLeft,
child: Icon(
Icons.delete_forever,
color: Colors.white,
size: 50.0,
),
),
secondaryBackground: Container(
padding:
EdgeInsets.symmetric(horizontal: 12.0),
color: Colors.red,
alignment: Alignment.centerRight,
child: Icon(
Icons.delete_forever,
color: Colors.white,
size: 50.0,
),
),
key: UniqueKey(),
onDismissed: (direction) async {
_showCircularProgressDelete(context);
if (await urlPublicaciones
.eliminarPublicacion(urlPosts[index])) {
setState(() {
publicaciones.removeAt(index);
});
Navigator.pop(context);
}
else {
Navigator.pop(context);
await _showErrorDialog(context);
}
},
child: _tarjeta(
context, publicaciones[index], index));
},
);
} else {
return Center(
child: Text(
'Aún no cuentas con ninguna publicación',
style: TextStyle(fontSize: 25.0),
textAlign: TextAlign.center));
}
} else {
return Center(child: CircularProgressIndicator());
}
},
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
Widget _tarjeta(
BuildContext context,
CategoriasResponse publicacion, int index) {
colores = _calculoPuntuacion(publicacion.calificacion.calificacion_total);
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.symmetric(horizontal: 10),
child: GestureDetector(
onTap: () {
Navigator.pushNamed(context, 'detalle_mipublicacion',
arguments: publicacion);
},
child: Card(
elevation: 10.0,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 10.0,
),
Container(
padding:
EdgeInsetsDirectional.fromSTEB(5.0, 10.0, 10.0, 0.0),
alignment: AlignmentDirectional.center,
child: _cargarImagen(publicacion)),
Column(
children: <Widget>[
SizedBox(
height: 28.0,
child: Text(
publicacion.nombre,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20.0),
textAlign: TextAlign.center,
)),
Text(
'Categoria: ' + publicacion.categoria,
style: TextStyle(
fontWeight: FontWeight.normal, fontSize: 15.0),
textAlign: TextAlign.center,
)
],
),
],
),
Column(
children: <Widget>[
SizedBox(
height: 35.0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.star, color: colores[0]),
Icon(Icons.star, color: colores[1]),
Icon(Icons.star, color: colores[2]),
Icon(Icons.star, color: colores[3]),
Icon(Icons.star, color: colores[4]),
Text(publicacion.calificacion.calificacion_total
.toString())
],
),
)
],
),
Column(
children: <Widget>[
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.phone, color: Colors.orangeAccent),
Text(publicacion.telefono.toString(),
overflow: TextOverflow.ellipsis)
],
),
]),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.location_on,
color: Colors.orangeAccent),
Text(publicacion.direccion,
overflow: TextOverflow.ellipsis)
],
),
]),
],
),
],
),
SizedBox(height: 10)
],
),
),
),
);
}
Widget _cargarImagen(CategoriasResponse publicacion) {
final logo = Container(
child: Card(
elevation: 5.0,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
child: ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: FadeInImage(
placeholder: AssetImage('assets/img/giphy.gif'),
image: NetworkImage(publicacion.fotos.url1),
height: 150.0,
width: 170.0,
fit: BoxFit.fill),
),
),
);
return logo;
}

Try this:
FutureBuilder(
future: urlPublicaciones.cargarUrlPublicaciones(),
builder: (BuildContext context,
AsyncSnapshot<List<UrlPublicacionesModel>> snapshotUrl) {
if (snapshotUrl.hasData) {
urlPosts = snapshotUrl.data;
return FutureBuilder(
future: urlPublicaciones.cargarPublicaciones(urlPosts),
builder: (BuildContext context,
AsyncSnapshot<List<CategoriasResponse>> snapshot) {
if (snapshot.hasData) {
publicaciones = snapshot.data;
if (publicaciones.isNotEmpty) {
return ListView.builder(
itemCount: publicaciones.length,
itemBuilder: (BuildContext context, int index) {
return Dismissible(
confirmDismiss: (direction) async {
switch (direction) {
case DismissDirection.endToStart:
return await _showConfirmationDialog(
context);
case DismissDirection.startToEnd:
return await _showConfirmationDialog(
context);
}
},
background: Container(
padding:
EdgeInsets.symmetric(horizontal: 12.0),
color: Colors.red,
alignment: Alignment.centerLeft,
child: Icon(
Icons.delete_forever,
color: Colors.white,
size: 50.0,
),
),
secondaryBackground: Container(
padding:
EdgeInsets.symmetric(horizontal: 12.0),
color: Colors.red,
alignment: Alignment.centerRight,
child: Icon(
Icons.delete_forever,
color: Colors.white,
size: 50.0,
),
),
key: UniqueKey(),
onDismissed: (direction) async {
_showCircularProgressDelete(context);
if (await urlPublicaciones
.eliminarPublicacion(urlPosts[index])) {
setState(() {
publicaciones.removeAt(index);
});
Navigator.pop(context);
}
else {
Navigator.pop(context);
await _showErrorDialog(context);
}
},
child: _tarjeta(
context, publicaciones[index], index));
},
);
} else {
return Center(
child: Text(
'Aún no cuentas con ninguna publicación',
style: TextStyle(fontSize: 25.0),
textAlign: TextAlign.center));
}
} else {
return Center(child: CircularProgressIndicator());
}
},
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),

Related

Passing data from page to page firebase flutter

I am trying to pass firebase snapshot data from first page to second page in flutter using GET. I'm able to pass data from one screen to another in debug mode but not in release mode.
I have used a streambuilder on the page and a Future on second . Please where am i going wrong ?
here is code..
first page:
Container(
child: Expanded(
child: StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Songs')
.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return Container(
color: Colors.white24,
padding: EdgeInsets.all(10),
child: ListView(
children: snapshot.data!.docs.map((document) {
return Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
side: BorderSide(
color: Colors.purple, width: 2)),
elevation: 4,
child: ListTile(
title: Text(document['title'],
style: TextStyle(fontSize: 16)),
subtitle: Text(
document['artist'],
style: TextStyle(color: Colors.purple),
),
onTap: () {
Get.to(() => DetailsPage(
piss: document,
post: document.id,
));
},
contentPadding: EdgeInsets.all(20),
leading: Image.asset('assets/logo.png'),
trailing: document['isNew'] == true
? Image.asset(
'assets/new.gif',
)
: null),
),
);
}).toList(),
),
);
}),
),
),
_banner == null
? Container()
: Container(
margin: const EdgeInsets.only(bottom: 12),
height: 52,
child: AdWidget(
ad: _banner!,
),
),
],
),
),
);
}
}
second page
FutureBuilder(
future: getData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return Expanded(
child: ListView.builder(
itemCount: widget.piss['tileHeaders'].length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
_index = index;
counter = counter + 1;
print('COUNTER: $counter');
if (counter == 3) {
_showRewardedAd();
_controller.play();
print("Counter is $counter");
counter = 0;
_createRewardedAd();
}
});
index > 0
? playIt(index)
: _controller
.load(widget.piss['videos'][index]);
},
child: Card(
elevation: 5,
child: Column(
children: [
Container(
height: 100,
child: Row(
children: [
Center(
child: Padding(
padding: EdgeInsets.all(10),
child: Expanded(
child: Image.asset(
"assets/logo.png"),
flex: 2,
// flex: 2,),
),
)),
Expanded(
child: Container(
alignment:
Alignment.topLeft,
child: Column(
children: [
Expanded(
flex: 5,
child: ListTile(
title: Text(
widget.piss[
'tileHeaders']
[index],
style: TextStyle(
fontSize:
26)),
),
),
Expanded(
flex: 5,
child: Row(
mainAxisAlignment:
MainAxisAlignment
.end,
children: [
Container(
child: widget
.piss[
'videos']
[
index]
.toString()
.contains(
'PL')
? Center(
child:
Container(child: playlist()),
)
: Center(
child:
Container(
child:
notPlaylist(),
),
),
),
],
))
],
)),
)
],
))
],
)),
);
}),
);
}
})
Please help

Implement pagination in Flutter with a bloc pattern

Using the NotificationListener, I am trying to integrate pagination with the ListView.Builder, but I don't get the expected result. While the list is working, it scrolls very slowly.
The code I wrote is below
NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (_controller.position.maxScrollExtent ==
_controller.offset) {
if (state is LoghistorySuccess) {
if (logsData.length == _index) {
if (pagecount > page) {
setState(() {
page = page + 1;
print(page);
BlocProvider.of<LogHistoryBloc>(
context)
.add(LogHistoryFetchEvent(
page: page));
});
}
}
}
}
if (scrollNotification
is ScrollStartNotification) {
_onStartScroll(scrollNotification.metrics);
} else if (scrollNotification
is ScrollUpdateNotification) {
_onUpdateScroll(scrollNotification.metrics);
} else if (scrollNotification
is ScrollEndNotification) {
_onEndScroll(scrollNotification.metrics);
}
return true;
},
child: logsData.isNotEmpty
? ListView.builder(
controller: _controller,
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: logsData.length,
//state.logHistoryModel.results?.logs?.length ?? 0,
itemBuilder: (context, index) {
return Padding(
padding:
const EdgeInsets.only(top: 12.0),
child: DottedBorder(
borderType: BorderType.RRect,
strokeWidth: 1,
dashPattern: [2.5, 2.5],
color:
HexColor(Constants.primary),
radius: Radius.circular(10),
child: Padding(
padding: const EdgeInsets.only(
top: 15.0,
left: 15,
right: 15,
bottom: 8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Container(
width: MediaQuery.of(
context)
.size
.width /
2,
child: Text(
"${logsData[index].date}",
style: TextStyle(
overflow:
TextOverflow
.ellipsis,
fontWeight:
FontWeight
.w500,
fontSize: 16,
color: HexColor(
Constants
.primary),
)),
),
// Text(
// "${state.logHistoryEntity.logs?[index]["entry_date"]}",
// style: TextStyle(
// color:
// Color(0xff555B5F)),
// ),
],
),
Container(
margin: EdgeInsets.only(
top: 15,
),
child: ListView.builder(
shrinkWrap: true,
physics:
NeverScrollableScrollPhysics(),
itemCount:
logsData[index]
.log
?.length ??
0,
//state.logHistoryModel.results?.logs?[index].log?.length ?? 0,
itemBuilder:
(context, _index) {
var _data =
logsData[index]
.log?[_index];
return Padding(
padding:
const EdgeInsets
.only(
bottom:
8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
InkWell(
onTap: () {
summaryPopUp(
context,
_data!);
},
child: Text(
"• ${_data?.startTime} to ${_data?.endTime}",
style: TextStyle(
color: Color(
0xff555B5F)),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Text(
"${_data?.logtype}",
style: TextStyle(
color:
Color(0xffED5B2E)),
),
SizedBox(
width: 20,
),
_data?.createdDate ==
formatted
? Row(
children: [
InkWell(
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => EditLogsScreen(log: _data!),
));
},
child: ImageIcon(
AssetImage("assets/icons/pencil.png"),
color: Color(0xff18A558),
size: 20,
),
),
SizedBox(
width: 8,
),
InkWell(
onTap: () {
showDialog(
context: context,
builder: (context) {
return DeletLogConfPopUp(
logId: _data?.id,
log: logsData[_index].log,
index: _index,
);
},
);
},
child: ImageIcon(
AssetImage("assets/icons/delete_icon.png"),
color: Color(0xffE72323),
size: 18,
),
),
],
)
: Container()
],
)
],
),
);
},
),
)
],
),
)),
);
},
)
: Container(),
// Center(
// child: Column(
// children: [
// Image(
// image: AssetImage(
// "assets/images/no_task.png")),
// Text("You don't have any logs yet")
// ],
// ),
// ),
)
with this code pagination works fine but not scrolling fast.

List view childs get out of container

I am trying to make a list view only occupy part of the screen, but it keeps growing till the end not respecting the contianer constraints. I tried to use a sizedbox too but it didn' work. List tiles outside the container are shown without any widget inside, but the background is shown anyways
#override
Widget build(BuildContext context) {
return FutureBuilder(
future: pedidos,
builder: (context, AsyncSnapshot<List<Pedido>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: ListView.builder(
itemCount: snapshot.data!.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Hero(
tag:
"pedidos_card${snapshot.data![index].idPedido}",
child: ListTile(
tileColor: Colors.white,
leading: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle),
child: Center(
child: Text(
style: Theme.of(context)
.textTheme
.headlineSmall,
"${snapshot.data![index].idPedido}"),
),
),
title: Text(
'Pedido: ${snapshot.data![index].idPedido}'),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10),
Text(
'Estado: ${snapshot.data![index].estadoPedido.last.tipoEstadoPedido.name}'),
SizedBox(height: 10),
Text(
"Cliente: ${snapshot.data![index].cliente.nombre}")
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
trailing: Checkbox(
value: pedidosSeleccion
.contains(snapshot.data![index]),
onChanged: (bool? value) {
// value = checkboxList[index];
// setState(() {});
},
),
onTap: () {
bool isSelected = pedidosSeleccion
.contains(snapshot.data![index]);
if (isSelected) {
pedidosSeleccion
.remove(snapshot.data![index]);
} else {
pedidosSeleccion.add(snapshot.data![index]);
}
setState(() {});
},
),
));
}),
),
ElevatedButton(
onPressed: () {}, child: Text('Ver ultima milla')),
],
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
});
}
}
example
you can use Expanded instead of Sizedbox
eg:-
Column(
children:[
Expanded(flex:9,
child: ListView(
padding: const EdgeInsets.only(top: 10.0),
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
),
),
Expanded(flex:1,
child:
ElevatedButton(
// fill in required params
),
)
])

Failing to get data from Firestore after Flutter Upgrades

I recently upgrade all the depencies. It required to change all my codes.
Now I face an issue to retrieve data from Firebase.
The main codes impacted are below.
BlocBuilder - cubit was replaced by bloc
BlocBuilder(
bloc: ordersBloc,
buildWhen: (previous, current) {
if (current is UpdateOrderAnalyticsState ||
current is GetOrderAnalyticsFailedState ||
current is GetOrderAnalyticsInProgressState) {
return true;
}
return false;
},
builder: (context, state) {
if (state is GetOrderAnalyticsInProgressState) {
return Shimmer.fromColors(
period: Duration(milliseconds: 800),
baseColor: Colors.grey.withOpacity(0.5),
highlightColor: CompanyColors.color[800].withOpacity(0.5),
child: ShimmerCommonMainPageSmallItem(size: size),
);
}
if (state is GetOrderAnalyticsFailedState) {
return Center(child: Text('FAILED'));
}
if (state is UpdateOrderAnalyticsState) {
orderAnalytics = state.orderAnalytics;
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Material(
child:
InkWell(
splashColor: CompanyColors.color[700].withOpacity(0.5),
onTap: () {
HapticFeedback.heavyImpact();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => InventoryPage()),
);
},
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 1),
child: Container(
padding: const EdgeInsets.all(10.0),
decoration: _mainthembox,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'GESTION INVENTAIRE',
overflow: TextOverflow.clip,
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
color: CompanyColors.color[50],
fontSize: 15,
fontWeight: FontWeight.w500,
),
),
SizedBox(
height: 5.0,
),
Container(
width: 55.0,
height: 55.0,
alignment: Alignment.center,
padding: const EdgeInsets.all(15.0),
decoration: _thembox,
child: Icon(
Icons.account_balance_outlined,
color: CompanyColors.color[50],
size: 25.0,
),
),
SizedBox(
height: 10.0,
),
],
),
),
),
),
),
),
),
CloudFirestore - documentSnapshot.data()['cancelledOrders'] was replaced by documentSnapshot.get('cancelledOrders')
class OrderAnalytics {
var cancelledOrders;
var cancelledSales;
var deliveredOrders;
var deliveredSales;
var newOrders;
var newSales;
var processedOrders;
var processedSales;
var totalOrders;
var totalSales;
OrderAnalytics({
this.cancelledOrders,
this.cancelledSales,
this.deliveredOrders,
this.deliveredSales,
this.newOrders,
this.newSales,
this.processedOrders,
this.processedSales,
this.totalOrders,
this.totalSales,
});
factory OrderAnalytics.fromFirestore(DocumentSnapshot documentSnapshot) {
return OrderAnalytics(
cancelledOrders: documentSnapshot.get('cancelledOrders'),
cancelledSales: documentSnapshot.get('cancelledSales'),
deliveredOrders: documentSnapshot.get('deliveredOrders'),
deliveredSales: documentSnapshot.get('deliveredSales'),
newOrders: documentSnapshot.get('newOrders'),
newSales: documentSnapshot.get('newSales'),
processedOrders: documentSnapshot.get('processedOrders'),
processedSales: documentSnapshot.get('processedSales'),
totalOrders: documentSnapshot.get('totalOrders'),
totalSales: documentSnapshot.get('totalSales'),
);
}
}
see below error messages

Gesture detector on tap not working in flutter release app but working in debug app

I am using firestore and created 4 cards on which the user taps on goes to the next screen. Everything is working fine in debug mode, in debug mode both Inkwell and Gesture Detector are working but when I make a release version I don't know why but both Inkwell and Gesture Detector are not working. Have no idea what's causing this. Please help.
class _RestaurantDashboardState extends State<RestaurantDashboard> {
Widget buildRestaurantCards(String title, IconData iconData, int orderCount) {
return Expanded(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
if (title == "Menu\nManagement") {
Navigator.push(context,
MaterialPageRoute(builder: (context) => MenuManagement()));
} else if (title == "Current Orders") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrderScreen("In Progress"),
),
);
} else if (title == "Order History") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrderHistory("In Progress"),
),
);
} else if (title == "Update Profile") {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RestaurantSignUp(Utils.restaurant!.restaurantId, true),
),
);
}
},
child: Container(
height: double.infinity,
child: Card(
margin: EdgeInsets.all(8),
elevation: 8,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
margin: EdgeInsets.only(top: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
orderCount > 0
? Row(
children: [
Container(
alignment: Alignment.center,
width: 30,
height: 30,
margin: EdgeInsets.all(4),
padding: EdgeInsets.all(4),
child: FittedBox(
child: Text(
orderCount.toString(),
style: TextStyle(
color: Colors.white, fontSize: 18),
)),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(16),
),
)
],
)
: SizedBox(),
Container(
margin: EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.centerRight,
child: Icon(
iconData,
size: 40,
),
),
],
),
),
Container(
width: double.infinity,
margin:
EdgeInsets.symmetric(horizontal: 16, vertical: 16),
alignment: Alignment.center,
child: FittedBox(
child: Text(
title,
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
)),
],
)),
),
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dashboard'),
),
body: Container(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * 0.25,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
isFirebaseInitialized
? StreamBuilder(
stream: FirebaseFirestore.instance
.collection("orders")
.snapshots(),
builder: (context,
AsyncSnapshot<
QuerySnapshot<Map<String, dynamic>>>
snapshot) {
if (!snapshot.hasData) {
setState(() {
_isLoading = false;
});
return Container();
}
if (snapshot.hasError) {
setState(() {
_isLoading = false;
});
}
List<DocumentSnapshot> itemsList = [];
for (DocumentSnapshot doc
in snapshot.data!.docs) {
if (doc['restaurantId'] ==
Utils.restaurant!.restaurantId &&
doc['orderStatus'] == "In Progress") {
itemsList.add(doc);
}
}
return buildRestaurantCards("Current Orders",
Icons.list_alt, itemsList.length);
},
)
: buildRestaurantCards(
"Current Orders", Icons.list_alt, 0),
buildRestaurantCards("Order History", Icons.history, 0),
],
),
),
Container(
height: MediaQuery.of(context).size.height * 0.25,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
buildRestaurantCards(
"Menu\nManagement", Icons.restaurant_menu_rounded, 0),
buildRestaurantCards("Update Profile", Icons.person, 0),
],
),
),
],
),
)
);
}
}
Check if there are any exceptions caught in the debug console, If there are then fix those, then the issue will be resolved