123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- import 'dart:io';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:carousel_slider/carousel_controller.dart' as cslider;
- import 'package:carousel_slider/carousel_slider.dart';
- import 'package:eitc_erm_app/select_clinic.dart';
- import 'package:eitc_erm_app/select_doctor.dart';
- import 'package:eitc_erm_app/select_patient.dart';
- import 'package:eitc_erm_app/utils/Component.dart';
- import 'package:eitc_erm_app/utils/Constants.dart';
- import 'package:eitc_erm_app/utils/Utils.dart';
- import 'package:eitc_erm_app/utils/logger.dart';
- import 'package:eitc_erm_app/widget/circular_loading.dart';
- import 'package:eitc_erm_app/widget/image_error.dart';
- import 'package:eitc_erm_app/widget/loading.dart';
- import 'package:eitc_erm_app/widget/marquee_widget.dart';
- import 'package:eitc_erm_app/widget/user_header.dart';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- import 'Introduce.dart';
- import 'bean/doctor_list.dart';
- import 'bean/hospital_detail.dart';
- import 'bean/notice_manage_list.dart';
- import 'bean/user_info.dart';
- import 'doctor_detail.dart';
- import 'login.dart';
- import 'notice_list.dart';
- /*void main() {
- WidgetsFlutterBinding.ensureInitialized();
- runApp(Home());
- }*/
- late BuildContext parentCxt;
- class Home extends StatefulWidget {
- Home(BuildContext context) {
- parentCxt = context;
- }
- @override
- State<StatefulWidget> createState() => HomeState();
- }
- class HomeState extends State<Home> {
- NoticeManageList mNoticeManageList = new NoticeManageList();
- List<String> noticeList = [" "];
- @override
- void initState() {
- super.initState();
- getInfo();
- noticeManageList();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- backgroundColor: Global.StatusBarColor,
- title: Text(
- Global.clinic,
- style: const TextStyle(color: Colors.white),
- ),
- centerTitle: true,
- actions: <Widget>[
- IconButton(
- color: Colors.white,
- icon: const Icon(
- Icons.loop,
- ),
- onPressed: () {
- Navigator.pushReplacement(
- context,
- MaterialPageRoute(
- builder: (context) => SelectClinic("fromHome")),
- );
- }),
- ],
- ),
- body: SafeArea(
- child: SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min, //横向大小
- crossAxisAlignment: CrossAxisAlignment.center, //纵向对齐方式
- children: [
- const Banner(),
- const Padding(
- padding: EdgeInsets.all(10),
- child: Row(children: [
- SizedBox(width: 1),
- Text(
- '▊',
- style: TextStyle(fontSize: 15, color: Colors.blue),
- ),
- SizedBox(width: 20),
- Text(
- '门诊服务',
- style: TextStyle(fontSize: 15),
- ),
- ])),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- //元素与空白互相间隔
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => SelectPatient("")),
- );
- },
- child: Container(
- decoration: BoxDecoration(
- color: Colors.green[300],
- border: Border.all(color: Colors.green)),
- width: 160,
- child: const Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- SizedBox(height: 10),
- Icon(
- Icons.account_balance_wallet_outlined,
- color: Colors.white,
- ),
- SizedBox(height: 10),
- Text("预约挂号",
- style: TextStyle(
- fontSize: 15, color: Colors.white)),
- SizedBox(height: 10),
- Text("点击在线预约挂号",
- style: TextStyle(
- fontSize: 15, color: Colors.white)),
- SizedBox(height: 10),
- ],
- ),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- // if(Global.selectDoctor == -1) {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => SelectDoctor("")),
- );
- /*} else {
- */ /*Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => ChatHome()),
- );*/ /*
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => OnlineConsultationDetail()),
- );
- }*/
- },
- child: Container(
- decoration: BoxDecoration(
- color: Colors.orange[300],
- border: Border.all(color: Colors.orange)),
- width: 160,
- child: const Column(children: [
- SizedBox(height: 10),
- Icon(
- Icons.chat_outlined,
- color: Colors.white,
- ),
- SizedBox(height: 10),
- Text("线上咨询",
- style: TextStyle(
- fontSize: 15, color: Colors.white)),
- SizedBox(height: 10),
- Text("点击在线咨询医生",
- style: TextStyle(
- fontSize: 15, color: Colors.white)),
- SizedBox(height: 10),
- ]),
- ),
- ),
- ),
- ],
- ),
- Padding(
- padding: const EdgeInsets.only(left: 6),
- child: Row(children: [
- const Icon(
- Icons.notifications,
- color: Colors.lightGreen,
- size: 18,
- ),
- const SizedBox(width: 18),
- Expanded(
- child: Container(
- alignment: Alignment.center,
- width: double.infinity,
- height: 24,
- child: noticeList.isNotEmpty
- ? buildMarqueeWidget(noticeList)
- : const Text(
- '',
- ),
- ),
- ),
- ])),
- const Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- SizedBox(width: 1),
- Text(
- '▊',
- style: TextStyle(fontSize: 15, color: Colors.blue),
- ),
- SizedBox(width: 20),
- Text(
- '医生推荐',
- style: TextStyle(fontSize: 15),
- ),
- /*SizedBox(width: 190),
- Text(
- '查看更多>>',
- style:
- const TextStyle(fontSize: 13, color: Colors.grey),
- ),*/
- ])),
- const DoctorRecommend(),
- ],
- ),
- ),
- ));
- }
- MarqueeWidget buildMarqueeWidget(List<String> loopList) {
- ///上下轮播 安全提示
- return MarqueeWidget(
- //子Item构建器
- itemBuilder: (BuildContext context, int index) {
- String itemStr = loopList[index];
- //通常可以是一个 Text文本
- return GestureDetector(
- onTap: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => NoticeList(mNoticeManageList)),
- );
- },
- child: Text(
- itemStr,
- style: const TextStyle(
- fontSize: 16,
- color: Colors.lightGreen,
- fontWeight: FontWeight.w700,
- ),
- ));
- },
- //循环的提示消息数量
- count: loopList.length,
- );
- }
- Future<UserInfo?> getInfo() async {
- logd(Global.token);
- final response =
- await http.get(Uri.parse('${Global.BaseUrl}user/getInfo'), headers: jsonHeaders(withToken: true));
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("用户信息=$json");
- UserInfo mUserInfo = UserInfo.fromJson(json);
- if (mUserInfo.code == Global.responseSuccessCode) {
- final data = mUserInfo.data;
- if (data != null) {
- Global.userId = data.id!;
- Global.userIdentificationCard = data.identificationCard!;
- Global.loginPhoneNo = data.phoneNumber!;
- Utils.saveData(
- "userIdentificationCard", Global.userIdentificationCard);
- Utils.saveData("loginPhoneNo", Global.loginPhoneNo);
- }
- } else {
- Component.toast(mUserInfo.msg.toString(), 0);
- }
- return mUserInfo;
- } else {
- Component.toast("获取用户信息出错!", 0);
- }
- }
- Future<NoticeManageList?> noticeManageList() async {
- Map<String, String> headers = {
- 'token': '${Global.token}',
- };
- final response = await http.get(
- Uri.parse('${Global.BaseUrl}notice-manage/list'),
- headers: headers);
- logd(response.body.toString());
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("公告=$json");
- mNoticeManageList = NoticeManageList.fromJson(json);
- if (mNoticeManageList.code == Global.responseSuccessCode) {
- noticeList.clear();
- for (int i = 0; i < mNoticeManageList.data!.length; i++) {
- String line = mNoticeManageList.data![i].noticeTitle.toString();
- if (line.length > 18) line = "${line.substring(0, 18)}...";
- noticeList.add(line);
- }
- setState(() {});
- return mNoticeManageList;
- } else {
- Component.toast(mNoticeManageList.msg.toString(), 0);
- }
- return null;
- } else {
- Component.toast("获取通知出错!", 0);
- return null;
- }
- }
- }
- class Banner extends StatefulWidget {
- const Banner({super.key});
- @override
- BannerState createState() => BannerState();
- }
- class BannerState extends State<Banner> {
- HospitalDetail mHospitalDetail = new HospitalDetail();
- @override
- void initState() {
- super.initState();
- fetchHospitalData();
- }
- Future<HospitalDetail?> fetchHospitalData() async {
- logd(Global.token);
- final response = await http
- .get(Uri.parse('${Global.BaseUrl}clinic-info/detail'), headers: jsonHeaders(withToken: true));
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("诊所详情=$json");
- mHospitalDetail = HospitalDetail.fromJson(json);
- if (mHospitalDetail.code == Global.responseSuccessCode) {
- if (mHospitalDetail.data != null) {
- if (mHospitalDetail.data?.bannerPic1 != null) {
- list.add(Global.ImageUrl + mHospitalDetail.data!.bannerPic1!);
- } else {
- list.add("");
- }
- if (mHospitalDetail.data?.bannerPic2 != null) {
- list.add(Global.ImageUrl + mHospitalDetail.data!.bannerPic2!);
- }
- if (mHospitalDetail.data?.bannerPic3 != null) {
- list.add(Global.ImageUrl + mHospitalDetail.data!.bannerPic3!);
- }
- }
- setState(() {});
- } else if (mHospitalDetail.code == 401 || mHospitalDetail.code == 403) {
- Navigator.pushReplacementNamed(parentCxt, '/login');
- } else {
- Component.toast(mHospitalDetail.msg.toString(), 0);
- }
- return mHospitalDetail;
- } else {
- Component.toast("获取顶部滚动条出错!", 0);
- }
- }
- final List list = [];
- int _current = 0;
- final cslider.CarouselSliderController _controller =
- cslider.CarouselSliderController();
- @override
- Widget build(BuildContext context) {
- if (list.isEmpty) {
- return const SizedBox(
- height: 250,
- );
- }
- if (list.length == 1) {
- return SizedBox(
- height: 250,
- child: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () => _gotoHspitalDetail(context),
- child: _getBannerImage(list[0]),
- ),
- );
- }
- return Stack(
- alignment: AlignmentDirectional.bottomCenter,
- children: [
- CarouselSlider.builder(
- carouselController: _controller,
- options: CarouselOptions(
- height: 250,
- autoPlay: true,
- viewportFraction: 1.0,
- autoPlayInterval: const Duration(seconds: 3),
- onPageChanged: (index, reason) {
- setState(() {
- _current = index;
- });
- },
- ),
- itemCount: list.length,
- itemBuilder: (BuildContext context, int index, int pageViewIndex) {
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- switch (index) {
- case 0:
- _gotoHspitalDetail(context);
- break;
- case 1:
- break;
- case 2:
- break;
- }
- },
- child: _getBannerImage(list[index]),
- );
- },
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: list.asMap().entries.map((entry) {
- return GestureDetector(
- onTap: () => _controller.animateToPage(entry.key),
- child: Container(
- width: 10.0,
- height: 10.0,
- margin:
- const EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: (Theme.of(context).brightness == Brightness.dark
- ? Colors.white
- : Colors.black)
- .withOpacity(_current == entry.key ? 0.9 : 0.4)),
- ),
- );
- }).toList(),
- ),
- ],
- );
- }
- void _gotoHspitalDetail(BuildContext context) {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) =>
- Introduce(hospitalDetail: mHospitalDetail, key: const Key(''))),
- );
- }
- Widget _getBannerImage(String url) {
- return CachedNetworkImage(
- imageUrl: url,
- width: double.infinity,
- fit: BoxFit.cover,
- progressIndicatorBuilder: (ctx, _, progress) => Circularloading(
- value: progress.progress,
- ),
- errorWidget: (ctx, _, __) => const ImageError(
- size: 80,
- ),
- );
- }
- }
- DoctorListEntity? data = DoctorListEntity();
- class DoctorRecommend extends StatefulWidget {
- const DoctorRecommend({super.key});
- @override
- State<StatefulWidget> createState() => DoctorRecommendState();
- }
- class DoctorRecommendState extends State<DoctorRecommend> {
- late Future<DoctorListEntity?> _future;
- late BuildContext cxt;
- @override
- void initState() {
- super.initState();
- _future = fetchData();
- }
- Future<DoctorListEntity?> fetchData() async {
- Map<String, String> headers = {
- 'token': Global.token,
- };
- final response =
- await http.get(Uri.parse('${Global.BaseUrl}doctor/list'), headers: jsonHeaders(withToken: true));
- logd(Uri.parse('${Global.BaseUrl}doctor/list'));
- if (response.statusCode == 200) {
- final json = decodeBodyToJson(response.bodyBytes);
- logd("推荐医生=$json");
- DoctorListEntity mDoctorListEntity = DoctorListEntity.fromJson(json);
- if (mDoctorListEntity.code == Global.responseSuccessCode) {
- return mDoctorListEntity;
- } else if (mDoctorListEntity.code == 401 ||
- mDoctorListEntity.code == 403) {
- Navigator.of(context).pop();
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => Login()),
- );
- return null;
- } else {
- Component.toast(mDoctorListEntity.msg.toString(), 0);
- return null;
- }
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- }
- }
- @override
- Widget build(BuildContext context) {
- cxt = context;
- return Center(
- child: FutureBuilder<DoctorListEntity?>(
- future: _future,
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- data = snapshot.data;
- return GridView.builder(
- padding: const EdgeInsets.all(10),
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
- //注意此行
- crossAxisCount: 2, //每行 widget 数量
- crossAxisSpacing: 10, //widget 水平之间的距离
- mainAxisSpacing: 10, //widget 垂直之间的距离
- ),
- itemCount: data?.data?.length,
- // itemCount: 2,
- itemBuilder: _customWidget,
- );
- } else if (snapshot.hasError) {
- return Text('Error: ${snapshot.error}');
- }
- return const ColorLoader();
- },
- ),
- );
- }
- Widget _customWidget(BuildContext context, int index) {
- return GestureDetector(
- onTap: () {
- Global.doctor = data!;
- Global.selectDoctor = index;
- Navigator.push(
- cxt,
- MaterialPageRoute(
- builder: (context) => DoctorDetail(
- doctorListEntity: data, key: const Key(''), which: index)),
- );
- },
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(color: Colors.grey),
- borderRadius: BorderRadius.circular(8),
- color: Colors.white,
- ),
- child: Column(
- children: [
- const SizedBox(
- height: 10,
- ),
- UserHeader(
- url: "${Global.ImageUrl}${data?.data?[index].avatar}",
- ),
- Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- data?.data?[index].nickName ?? "",
- style: Theme.of(context).textTheme.titleMedium,
- ),
- Text(
- "${data?.data?[index].deptName ?? ""} ${data?.data?[index].postNames ?? ""}",
- overflow: TextOverflow.ellipsis,
- style: Theme.of(context).textTheme.bodyMedium,
- )
- ],
- ),
- const Spacer(),
- Padding(
- padding: const EdgeInsets.only(bottom: 10),
- child: _getProficientWidget(
- context, data?.data?[index].doctorProficient),
- ),
- ],
- ),
- ),
- );
- }
- Widget _getProficientWidget(BuildContext context, String? proficients) {
- if (proficients == null || proficients.isEmpty) {
- return const SizedBox();
- }
- List<String> list = proficients.split(",");
- Widget row;
- if (list.isNotEmpty) {
- row = Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- _getProficientItem(list, 0,
- list.length > 1 ? Alignment.centerRight : Alignment.center),
- Visibility(
- visible: list.length > 1,
- child: const SizedBox(
- width: 10,
- )),
- Visibility(
- visible: list.length > 1,
- child: _getProficientItem(list, 1, Alignment.centerLeft),
- ),
- ],
- );
- } else {
- row = const SizedBox();
- }
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 5),
- child: row,
- );
- }
- Widget _getProficientItem(List<String> list, int index, Alignment alignment) {
- if (list.length <= index) {
- return const SizedBox();
- }
- return Expanded(
- child: Align(
- alignment: alignment,
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(30),
- color: Colors.lightBlueAccent),
- child: Text(
- textAlign: TextAlign.center,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- list[index],
- style: const TextStyle(color: Colors.white, fontSize: 10),
- ),
- ),
- ));
- }
- }
|