I am trying to code a small flutter project and I am falling on this error and don't understand why. I have tried all the online solution but still getting the error. It occurs every time I click on the delete in the showCupertinoDialog it shows this error without crashing the app
BoxConstraints forces an infinite height.
These invalid constraints were provided to _RenderColoredBox's layout() function by the following function, which probably computed the invalid constraints in question:
RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:277:14)
The offending constraints were: BoxConstraints(w=358.0, h=Infinity)
And below is my code
class DashboardRestaurant extends StatefulWidget {
const DashboardRestaurant({Key? key}) : super(key: key);
static String id = 'dashboard_restaurant';
@override
_DashboardRestaurantState createState() => _DashboardRestaurantState();
}
class _DashboardRestaurantState extends State<DashboardRestaurant> {
final Stream<QuerySnapshot> activities = FirebaseFirestore
.instance.collection('activities')
.where('Type', isEqualTo: 'Restaurant')
.orderBy('ts', descending: true)
.snapshots();
bool showSpinner = false;
@override
Widget build(BuildContext context) {
return LoadingOverlay(
isLoading: showSpinner,
opacity: 0.5,
color: Colors.green,
progressIndicator: const CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.green),
),
child:Column(
children:[
AddButton(
title: 'Restaurants',
addLabel: 'Add Restaurant',
onPressed: (){
Navigator.pushNamed(context, RestaurantMainForm.id);
},),
const SizedBox(
height: 16.0,
),
const Divider(
color: Colors.white70,
height:40.0,
),
StreamBuilder<QuerySnapshot>(
stream: activities,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
return const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.green),
),
);
}
final data = snapshot.requireData;
if(data != null){
return ConstrainedBox(
constraints: const BoxConstraints.tightFor(
width: 360,
height: 250,
),
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: data.size,
itemBuilder: (context, index){
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
backgroundColor: Colors.transparent,
radius: 40,
child:data.docs[index] == null ? Image.asset('assets/images/image.png') : Image.network(
data.docs[index]['PhotoUrl'],
fit: BoxFit.cover,
) ,
),
Text( data.docs[index]['Name'], style:const TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold),
),
if(Responsive.isWeb(context))
const SizedBox(
width: 50,
),
Responsive.isWeb(context) ? ButtonBlue(
addLabel: 'View Restaurant',
color: Colors.green,
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context){
return ViewRestaurant(
restaurant: data.docs[index],
);
}));
},
icon: const Icon(IconData(61161, fontFamily: 'MaterialIcons')),
) : InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context){
return ViewRestaurant(
restaurant: data.docs[index],
);
}));
},
child: const Icon(IconData(61161, fontFamily: 'MaterialIcons')),
),
Responsive.isWeb(context) ? ButtonBlue(
addLabel: 'Delete Restaurant',
color: Colors.red,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context){
return ShowDialog(
deleteFunction: () async{
await FirebaseFirestore.instance.runTransaction((Transaction myTransaction) async {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl3']).delete().then((value) {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl2']).delete().then((value){
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl']).delete();
});
});
myTransaction.delete(snapshot.data!.docs[index].reference);
});
},
dialogTitle: "Delete",
dialogContent: "Do you really want to delete ${data.docs[index]['Name']} restaurant?",
);
});
},
icon: const Icon(Icons.delete_outline,),
): InkWell(
onTap: (){
if(defaultTargetPlatform == TargetPlatform.iOS){
showCupertinoDialog(
context: context,
builder: (BuildContext context){
return ShowDialog(
deleteFunction: () async{
setState(() {
showSpinner = true;
});
await FirebaseFirestore.instance.runTransaction((Transaction myTransaction) async {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl3']).delete().then((value) {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl2']).delete().then((value){
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl']).delete();
});
});
myTransaction.delete(snapshot.data!.docs[index].reference);
}).then((value) {
setState(() {
showSpinner = false;
});
showToast(message: 'Deleted Successfully', color: Colors.green);
Navigator.pop(context);
});
},
dialogTitle: "Delete",
dialogContent: "Do you really want to delete ${data.docs[index]['Name']} restaurant?",
);
});
}
else {
showDialog(
context: context,
builder: (BuildContext context){
return ShowDialog(
deleteFunction: () async{
setState(() {
showSpinner = true;
});
await FirebaseFirestore.instance.runTransaction((Transaction myTransaction) async {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl3']).delete().then((value) {
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl2']).delete().then((value){
FirebaseStorage.instance.refFromURL(data.docs[index]['PhotoUrl']).delete();
});
});
myTransaction.delete(snapshot.data!.docs[index].reference);
}).then((value) {
setState(() {
showSpinner = false;
});
showToast(message: 'Deleted Successfully', color: Colors.green);
Navigator.pop(context);
});
},
dialogTitle: "Delete",
dialogContent: "Do you really want to delete ${data.docs[index]['Name']} restaurant?",
);
});
}
},
child: const Icon(Icons.delete_outline,),
),
],
),
const Divider(
color: Colors.white70,
height:40.0,
),
],
);
}),
);
}
return const Center(
child: CircularProgressIndicator(),
);
},
)
],
),
);
}
}
I have tried all the online solutions and nothing really working for me. Can anyone help me please
CodePudding user response:
Try below formated code hope its help to you. add your Inside Column
widgets wrap it with Expanded
or Flexible
Column(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Container(
width: 100.0,
color: Colors.blue,
child: Text('Hello Flutter'),
),
),
],
),