我制作了两个小部件并在 main.dart 中调用它们。我希望课堂上的AntiRaggingCell
小部件HomePage
能够获取不同字符串的详细信息,例如姓名、标签、部门、电话号码、联系人和电子邮件。我的代码现在要做的是,我必须把每一个细节都放进去,AntiRaggingDetailChip
这样代码就会变得混乱。
我的代码,
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
final Color antiRaggingCellBorderColor = Color(0xFFE6E6E6);
final Color chipBackgroundColor = Color(0xFFF6F6F6);
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Squad',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Squad'),
),
body: SafeArea(
child: ListView.builder(
itemBuilder: (context, index) {
return Column(
children: <Widget>[
AntiRaggingCell(),
AntiRaggingCell(),
AntiRaggingCell(),
AntiRaggingCell(),
AntiRaggingCell(),
],
);
},
shrinkWrap: true,
itemCount: 1,
physics: ClampingScrollPhysics(),
),
),
);
}
}
class AntiRaggingCell extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
border: Border.all(color: Colors.black),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Center(
child: Wrap(
alignment: WrapAlignment.spaceEvenly,
spacing: 8.0,
children: <Widget>[
AntiRaggingDetailChip(Icons.person, 'Maruf Hassan'),
AntiRaggingDetailChip(Icons.label, 'Chairman'),
AntiRaggingDetailChip(Icons.mail, 'maruf@gmail.com'),
AntiRaggingDetailChip(Icons.phone, '1234567890'),
Center(
child: AntiRaggingDetailChip(Icons.account_balance,
'Computer Science & Engineering'),
),
],
),
),
],
),
),
),
),
],
);
}
}
class AntiRaggingDetailChip extends StatelessWidget {
final IconData iconData;
final String label;
AntiRaggingDetailChip(this.iconData, this.label);
@override
Widget build(BuildContext context) {
return RawChip(
label: Text(label),
labelStyle: TextStyle(color: Colors.black, fontSize: 14.0),
backgroundColor: chipBackgroundColor,
avatar: Icon(iconData),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
);
}
}
我希望这段代码接受这样的输入
body: SafeArea(
child: ListView.builder(
itemBuilder: (context, index) {
return Column(
children: <Widget>[
AntiRaggingCell('Aman Khan','Member','abc@gmail.com','123545894', 'MTECH'),
AntiRaggingCell('Wasim Khan','President','abc@gmail.com','123545894'),
AntiRaggingCell('Afzal Khan','Member','abc@gmail.com','123545894'),
AntiRaggingCell('Arman Khan','Member','abc@gmail.com','123545894'),
AntiRaggingCell('Kalam Khan','Member','abc@gmail.com','123545894'),
],
);
},