import 'package:flutter/material.dart';标签:columnRecords,return,index,Text,extends,5.22,override From: https://www.cnblogs.com/kongxiangzeng/p/18246568
import 'package:dio/dio.dart';
import '../Do/UserDao.dart';
class ColumnRecordsApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ColumnRecordsPage(),
);
}
}
class ColumnRecordsPage extends StatefulWidget {
@override
_ColumnRecordsPageState createState() => _ColumnRecordsPageState();
}
class _ColumnRecordsPageState extends State<ColumnRecordsPage> {
List<dynamic> columnRecords = [];
@override
void initState() {
super.initState();
fetchData();
}
void fetchData() {
fetchColumnRecords().then((records) {
setState(() {
columnRecords = records;
});
}).catchError((error) {
print(error);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("匿名天堂"),
),
body: ListView.builder(
itemCount: columnRecords.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(columnRecords[index]['user_name'].toString()),
subtitle: Text(
'Text: ${columnRecords[index]['text']}, Date: ${columnRecords[index]['date']}, Number: ${columnRecords[index]['number']}',
// 这里将所有的 subtitle 字段整合到一个 Text 组件中
),
);
},
),
);
}
}