import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
var items = [
"https://github.com/AmmarMohib/Economic-app/blob/master/lib/1.jpeg?raw=true",
"https://github.com/AmmarMohib/Economic-app/blob/master/lib/2.jpeg?raw=true",
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/3.jpeg",
"https://raw.githubusercontent.com/AmmarMohib/Economic-app/master/lib/4.jpeg"
];
var text =[
"Iphone 12",
"Iphone 12",
"Iphone 12",
"Iphone 12"
];
var reviews =[
"5.0 (23 reviews)",
"5.0 (23 reviews)",
"5.0 (23 reviews)",
"5.0 (23 reviews)"
];
var pie =[
"20 Pieces",
"20 Pieces",
"20 Pieces",
"20 Pieces"
];
var price =[
'90 dollar',
'90 dollar',
'90 dollar',
'90 dollar'
];
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Economic app",
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text("Economic app",style: TextStyle(color: Colors.black,fontFamily: 'Lobster',fontWeight: FontWeight.w600,fontSize: 30),),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.notifications_active,
color: Colors.black,
),
onPressed: () {
print(Text("hello"));
},
)
],centerTitle: true,backgroundColor: Colors.white,
),
body:GridView.count(
childAspectRatio: (45/15),
crossAxisCount: 1,
mainAxisSpacing: 7.5,
children: List.generate(items.length , (index) {
return Padding(
padding: const EdgeInsets.only(left:15,right: 15.0,top: 20.0),
child:ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
child: Center(child: Column(
children: [
GridTile(
child: Title(
color: Colors.red,
child: Row(
children: [
Image.network(items[index],height: 100,),
Padding(
padding: const EdgeInsets.only(bottom:75.0,left: 5),
child: Text(text[index],style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),),
),
Container(
transform: Matrix4.translationValues(-105.0, -4, 0.0),
child: IconButton(
icon: Icon(
Icons.star_border_purple500,
color: Colors.yellow,
),
onPressed: () {
},
),
),
Container(transform: Matrix4.translationValues(-110.0, -4, 0.0),child: Text( reviews[index])),
Container(transform: Matrix4.translationValues(-230.0, 25, 0),child: Text(pie[index])),
Container(transform: Matrix4.translationValues(-162.0, -4, 0),child: Text(price[index],style: TextStyle(color: Colors.purple,fontSize: 15),),),
],
)
)),
])
),
),
),
);
})
)
),
);
}
}
这是我的代码,问题是当我在 400px 或更少的移动设备上运行应用程序时,它抛出错误帽子 A RenderFlex 在右侧溢出了 93 个像素。不是解决
.我试过了,但没有解决。我想你会理解我的问题并给我解决方案。请帮我解决这个问题,非常感谢。
答案 0 :(得分:1)
只需使用 Column
和 Row
而不是使用 Transform
看下面的代码:
GridTile(
child: Title(
color: Colors.red,
child: Row(
children: [
Image.network(
items[index],
height: 100,
),
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
left: 15,
),
child: Text(
text[index],
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
Row(
children: [
IconButton(
icon: Icon(
Icons.star_border_purple500,
color: Colors.yellow,
),
onPressed: () {},
),
SizedBox(width: 5),
Text(reviews[index]),
SizedBox(width: 5),
Text(
price[index],
style: TextStyle(
color: Colors.purple,
fontSize: 15,
),
),
],
),
Container(
margin: EdgeInsets.only(left: 15),
child: Text(pie[index]),
),
],
),
],
),
),
),