我有问题在这里,我想所有的行显示,但当我运行应用程序时,它只显示一行,但我有6或7行在我的数据库中,我试图运行代码的输出来像这个截图:-
我希望输出如下截图:-
这是我的代码:
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: 300,
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
)),
),
///end logo
SizedBox(
height: 35,
),
///start Section
Container(
margin: EdgeInsets.only(left: 10, right: 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(
"${list[i]["book_name"]}",
style: TextStyle(
fontSize: 20,
color: Colors.black87),
),
SizedBox(
height: 20,
),
Row(
children: [
Text("${list[i]["collage"]}"),
Icon(Icons.perm_identity_rounded)
],
),
SizedBox(
height: 5,
),
Row(
children: [
Text("${list[i]["loc"]}"),
Column(
children: [Icon(Icons.store)],
)
],
),
],
),
)
],
)
//end logo
)),
),
SizedBox(
height: 35,
),
],
));
})));
}
}
我试图使标志在另一行(),但我不知道它是如何工作的
2条答案
按热度按时间t40tm48m1#
你正在使用
listView
内listView
而不是column
的主要问题。你还使用了一些小部件不正确,这将不会正确的响应移动的应用程序。尝试这个我更新了你的代码。对于顶部的广告视图,您需要将其放置在ListView之外,这样它将只显示一次。
请尝试此代码:
flseospp2#
问题是因为你把我的广告放在
ListView.builder
中,你需要把我的广告从ListView.builder
中移除。正确的方法应该是