select_hospital.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:typed_data';
  4. import 'package:eitc_erm_app/login.dart';
  5. import 'package:eitc_erm_app/utils/Constants.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:fluttertoast/fluttertoast.dart';
  8. import 'package:http/http.dart' as http;
  9. import 'bean/message_box_s_list_entity.dart';
  10. import 'bean/pda_patrol_time_list.dart';
  11. void main() {
  12. WidgetsFlutterBinding.ensureInitialized();
  13. runApp(SelectHospital());
  14. }
  15. class SelectHospital
  16. extends StatefulWidget {
  17. @override
  18. State<StatefulWidget> createState() => SelectHospitalState();
  19. }
  20. class SelectHospitalState extends State<SelectHospital> {
  21. ValueNotifier<dynamic> result = ValueNotifier(null);
  22. late Future<List<DataList>?> _future;
  23. @override
  24. void initState() {
  25. super.initState();
  26. _future = fetchData();
  27. }
  28. Future<List<DataList>?> fetchData() async {
  29. final response = await http.get(
  30. Uri.parse(
  31. '${Global.ServerUrl}/getPdaPatrolTimeList'),
  32. headers: {
  33. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8"
  34. });
  35. if (response.statusCode == 200) {
  36. final jsonString = utf8.decode(response.bodyBytes);
  37. final jsonResponse = jsonDecode(jsonString);
  38. print(jsonResponse);
  39. PdaPatrolTimeList mPatrolTime =
  40. new PdaPatrolTimeList.fromJson(jsonResponse);
  41. return mPatrolTime.data?[0].dataList;
  42. } else {
  43. Fluttertoast.showToast(
  44. msg: "出错了,请稍后再试!",
  45. toastLength: Toast.LENGTH_SHORT,
  46. gravity: ToastGravity.CENTER,
  47. timeInSecForIosWeb: 1,
  48. backgroundColor: Colors.blue,
  49. textColor: Colors.white,
  50. fontSize: 16.0);
  51. }
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return MaterialApp(
  56. home: Scaffold(
  57. appBar: AppBar(title: Text('请选择您需要挂号的医院/诊所'), centerTitle: true),
  58. body: Center(
  59. child: FutureBuilder<List<DataList>?>(
  60. future: _future,
  61. builder: (context, snapshot) {
  62. if (snapshot.hasData) {
  63. List<DataList>? data = snapshot.data;
  64. return ListView.builder(
  65. itemCount: data?.length,
  66. itemBuilder: (context, index) {
  67. return ListTile(
  68. title: Text(
  69. textAlign: TextAlign.center,
  70. '| 智汇口腔诊所 ' +
  71. (data?[index].startTime as String)),
  72. // subtitle: Text(' 巡检人:' +
  73. // (data?[index].patrolPersons as String) +
  74. // '\n ${(data?[index].finishNumber.toString())}个点位已处理\n 异常数:${(data?[index].errorNumber.toString())}个'),
  75. onTap: () {
  76. Navigator.push(
  77. context,
  78. MaterialPageRoute(builder: (context) => Login()),
  79. );
  80. },
  81. );
  82. },
  83. );
  84. } else if (snapshot.hasError) {
  85. return Text('Error: ${snapshot.error}');
  86. }
  87. return CircularProgressIndicator();
  88. },
  89. ),
  90. ),
  91. ),
  92. );
  93. }
  94. }