我正在尝试使用Flutter开发一个移动应用程序,我使用swagger生成了包含所有Web服务的Dart文件代码生成。我想从Web服务中获取所有用户的列表。 在屏幕上,我想为每个用户显示:图像,名字,姓氏和电子邮件。 我已经在main.dart中准备了如下的UI:
import 'package:flutter/material.dart';
import './utility.dart';
void main() => runApp(ListUserApp());
class ListUserApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'User List 4Motors',
home: ListUserScreen(),
);
}
}
class ListUserScreen extends StatefulWidget {
@override
State createState() {
return ListUserScreenState();
}
}
class ListUserScreenState extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: Scaffold(
appBar: AppBar(
title: Text('User List 4Motors'),
),
body: _buildListUser(),
),
);
}
Widget _buildListUser() {
Utility test = new Utility();
print(test.getFirstNameUser());
return ListView.builder(
itemBuilder: (context, position) {
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
margin: const EdgeInsets.all(10.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(right: 15.0),
child: Image(
width: 65, image: AssetImage('assets/person.jpeg')), // Image of user
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'firstname & lastname', // first and last name of user
style: TextStyle(
fontSize: 22,
),
),
Container(
margin: const EdgeInsets.all(5.0),
child: Text('email'), // Email of user
),
],
),
],
),
),
),
);
});
}
}
并且,以下由swagger生成的用户模型:
part of swagger.api;
class UsersData {
String id = null;
String firstName = null;
String lastName = null;
String email = null;
String phone = null;
String image = null;
DateTime birthDay = null;
String fireBaseID = null;
String dealerID = null;
String type = null;
<