Flutter新手不知道如何根据之前列表中的专业建立医生的ListView



我有一个医疗专业列表显示在ListView中,我希望能够点击一个专业,然后显示该专业医生的列表视图。如果我点击"心脏病专家"向医生展示心脏病专家。我不能让它工作。我有专科班,医生班,医生名单和专科名单。我把我的代码搞得一团糟,甚至不能在这里发布。你能告诉我如何显示"专业列表"并单击某个专业,然后导航并构建与所选专业匹配的"医生列表"吗?非常感谢!!!

这里的类别和列表:

class Doctors {
String name;
String specialty;
Doctors({
this.name,
this.specialty,
});
}
List<Doctors> dummyDoctors = [
Doctors(
name: "Susan Finn",
specialty: "Surgery",
),
Doctors(
name: "Mike Donovan",
specialty: "Cardiology",
),
Doctors(
name: "Tom Sharp",
specialty: "Dermatology",
),
];
class Specialties{
final String specialty;
Specialties({
this.specialty
});
}
List<Specialties> specialties = [
Specialties(
specialty: 'Surgery',
),
Specialties(
specialty: 'Cardiology',
),
Specialties(
specialty: 'Dermatology',
),
];

这是我所有的混乱和需要知道/理解的,这:

import 'package:flutter/material.dart';
import 'package:training2/specialty_modelo.dart';
import 'package:training2/second_screen.dart';
class SpecialtyScreen extends StatelessWidget {
String get specialty => null;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
height: 300.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: specialties.length,
itemBuilder: (BuildContext context, int index) {
Specialties specialties = specialties[index];
return GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => SecondRoute(
specialties: specialties)),),
child: Container(
margin: EdgeInsets.all(10.0),
width: 210.0,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
specialty,
style: TextStyle(
color: Colors.grey,
),
),
],
),
],
),
),
);
},
),
),
],
);
}
}

Zvi Karp建议在第二个屏幕上显示医生的专业知识,但运气不好,无法使用

import 'package:flutter/material.dart';
import 'package:training2/specialty_modelo.dart';
class SecondRoute extends StatelessWidget {
//final specialtyDoctorsList allDoctors;
SecondRoute({
this.specialty, Specialties specialties,
});
final String specialty;
get allDoctors => null;
@override
Widget build(BuildContext context) {
List<Doctors> specialtyDoctorsList = allDoctors.where((Doctors doctor) => doctor.specialty == this.specialty);
return Container();
}
}

根据注释,在第一页中调用第二页并将所选专业传递给它,如下所示:

Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute(specialty: specialty)),
);

然后在第二页中获得专业作为论据:

class SecondRoute extends StatelessWidget {
SecondRoute({
this.specialty,
});
final String specialty;

现在你可以使用它来获得特定的医生:

@override
Widget build(BuildContext context) {
List<Doctors> specialtyDoctorsList = allDoctors.where((Doctors doctor) => doctor.specialty == this.specialty);
return Container();
}

相关内容

  • 没有找到相关文章

最新更新