123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- import 'dart:convert';
- import 'dart:io';
- import 'package:dio/dio.dart';
- import 'package:eitc_erm_app/chat/chat_home.dart';
- import 'package:eitc_erm_app/utils/Component.dart';
- import 'package:eitc_erm_app/utils/Constants.dart';
- import 'package:file_picker/file_picker.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:permission_handler/permission_handler.dart';
- import 'bean/normal_response.dart';
- import 'bean/normal_response2.dart';
- import 'package:http/http.dart' as http;
- void main() {
- WidgetsFlutterBinding.ensureInitialized();
- runApp(OnlineConsultation());
- }
- class OnlineConsultation extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => OnlineConsultationState();
- }
- class OnlineConsultationState extends State<OnlineConsultation> {
- List<String> uploadImg = ["assets/images/upload_photo.png"];
- TextEditingController resourceController = TextEditingController();
- String age = "请选择年龄";
- String sex = "请选择性别";
- List<int> ageList = List.generate(101, (index) => index);
- @override
- void initState() {
- super.initState();
- // initPlatformState();
- }
- Future<void> initPlatformState() async {
- //相机权限
- if (await requestCameraPermission() == false) {
- return;
- }
- //录音权限
- if (await requestMicrophonePermission() == false) {
- return;
- }
- }
- Future<bool> requestCameraPermission() async {
- var status = await Permission.camera.status;
- if (status == PermissionStatus.granted) {
- return true;
- } else {
- status = await Permission.camera.request();
- if (status == PermissionStatus.granted) {
- return true;
- } else {
- return false;
- }
- }
- }
- Future<bool> requestMicrophonePermission() async {
- var status = await Permission.microphone.status;
- if (status == PermissionStatus.granted) {
- return true;
- } else {
- status = await Permission.microphone.request();
- if (status == PermissionStatus.granted) {
- return true;
- } else {
- return false;
- }
- }
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: Scaffold(
- resizeToAvoidBottomInset: false,
- backgroundColor: Global.BackgroundColor,
- appBar: new AppBar(
- title: new Text('在线问诊',
- style: TextStyle(
- color: Colors.white,
- )),
- centerTitle: true,
- elevation: 0.5,
- backgroundColor: Global.StatusBarColor,
- leading: new IconButton(
- tooltip: '返回上一页',
- icon: const Icon(
- Icons.arrow_back_ios,
- color: Colors.white,
- ),
- onPressed: () {
- Navigator.of(context).pop();
- //_nextPage(-1);
- },
- ),
- ),
- body: SingleChildScrollView(
- child: Container(
- padding: EdgeInsets.all(10),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '问诊资料',
- style: TextStyle(
- fontSize: 20, color: Colors.black),
- ),
- ]),
- ),
- ClipRRect(
- borderRadius: BorderRadius.circular(10.0),
- child: Container(
- color: Colors.white,
- padding: const EdgeInsets.all(10),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- /*Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '挂号费',
- style: TextStyle(
- fontSize: 15, color: Colors.grey),
- ),
- Text(
- '¥12.5',
- style: TextStyle(fontSize: 15),
- ),
- ]),
- ),*/
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '就诊人',
- style: TextStyle(
- fontSize: 15,
- color: Colors.grey),
- ),
- Text(
- Global
- .patient
- .data![Global.selectPatient]
- .patientName
- .toString(),
- style: TextStyle(fontSize: 15),
- ),
- ]),
- ),
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '年龄',
- style: TextStyle(
- fontSize: 15,
- color: Colors.grey),
- ),
- GestureDetector(
- onTap: () {
- selectItem(ageList, 0);
- },
- child: Row(children: <Widget>[
- Text(
- age,
- style: TextStyle(
- color: Colors.black,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: Colors.black,
- ),
- ])),
- ]),
- ),
- Padding(
- padding: EdgeInsets.all(10),
- child: GestureDetector(
- onTap: () {
- selectItem(['男', '女'], 1);
- },
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '性别',
- style: TextStyle(
- fontSize: 15,
- color: Colors.grey),
- ),
- Row(children: <Widget>[
- Text(
- sex,
- style: TextStyle(
- color: Colors.black,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: Colors.black,
- ),
- ])
- ]),
- ),
- ),
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '咨询医生',
- style: TextStyle(
- fontSize: 15,
- color: Colors.grey),
- ),
- Text(
- Global
- .doctor
- .data![Global.selectDoctor]
- .nickName
- .toString(),
- style: TextStyle(fontSize: 15),
- ),
- ]),
- ),
- ]),
- ),
- ),
- SizedBox(height: 8),
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Text(
- '病情资料',
- style: TextStyle(
- fontSize: 20, color: Colors.black),
- ),
- ]),
- ),
- ClipRRect(
- borderRadius: BorderRadius.circular(10.0),
- child: Container(
- color: Colors.white,
- padding: const EdgeInsets.all(10),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.all(10),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Expanded(
- child: TextField(
- maxLines: 5,
- enabled: true,
- controller: resourceController,
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- hintText:
- '请简单描述病情,录入:主要症状、发病时间、治疗过程、病情变化、想得到什么样的帮助等',
- ),
- ),
- ),
- ]),
- ),
- ]),
- ),
- ),
- Padding(
- padding: EdgeInsets.all(5),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- '上传患处、病历、检查单等照片',
- style: TextStyle(fontSize: 10),
- ),
- SizedBox(height: 3),
- GridView.builder(
- padding: const EdgeInsets.all(10),
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- gridDelegate:
- const SliverGridDelegateWithFixedCrossAxisCount(
- //注意此行
- crossAxisCount: 3, //每行 widget 数量
- crossAxisSpacing: 10, //widget 水平之间的距离
- mainAxisSpacing: 10, //widget 垂直之间的距离
- ),
- itemCount: uploadImg.length,
- // itemCount: 2,
- itemBuilder: _customWidget,
- ),
- /*GestureDetector(
- onTap: () {
- uploadFile();
- },
- child:
- Image(
- image: AssetImage('assets/images/upload_photo.png'),
- ),),*/
- ]),
- ),
- ElevatedButton(
- child: Text("下一步",
- style: TextStyle(
- color: Colors.white, fontSize: 15)),
- style: ButtonStyle(
- backgroundColor:
- MaterialStateProperty.resolveWith<Color>(
- (states) {
- return Colors.blue; // Regular color
- }),
- fixedSize: MaterialStateProperty.all<Size>(
- Size(MediaQuery.of(context).size.width - 30,
- 30), // 设置宽度和高度
- ),
- ),
- onPressed: () {
- editChatDisease();
- },
- ),
- ])))));
- }
- Widget _customWidget(BuildContext context, int index) {
- return GestureDetector(
- onTap: () {
- if (index == 0) {
- uploadFile();
- }
- },
- child: Container(
- child: Expanded(
- child: Column(
- children: [
- index == 0
- ? Image(
- image: AssetImage(
- 'assets/images/upload_photo.png',
- ),
- width: 80,
- )
- : Image.network(
- // 图片地址
- uploadImg[index],
- width: 80,
- fit: BoxFit.cover,
- excludeFromSemantics: true,
- errorBuilder: (context, error, stackTrace) => Icon(
- Icons.image,
- size: 80,
- color: Colors.grey,
- ),
- loadingBuilder: (context, child, loadingProgress) {
- if (loadingProgress == null) return child;
- return Center(
- child: CircularProgressIndicator(
- value: loadingProgress.expectedTotalBytes != null
- ? loadingProgress.cumulativeBytesLoaded /
- loadingProgress.expectedTotalBytes!
- : null,
- ),
- );
- },
- ),
- ],
- ),
- ),
- ),
- );
- }
- void uploadFile() async {
- FilePickerResult? result = await FilePicker.platform.pickFiles();
- if (result != null) {
- String fileName = result.files.single.name;
- String? filePath = result.files.single.path;
- FormData formData = FormData.fromMap({
- "file": await MultipartFile.fromFile(filePath!, filename: fileName),
- "path": "chat",
- });
- try {
- Map<String, String> headers = {
- 'token': '${Global.token}',
- };
- Response response = await Dio().post(
- Global.BaseUrl + 'common/minioUploadImage',
- data: formData,
- options: Options(headers: headers));
- print(response.data);
- if (response.statusCode == 200) {
- Normal2Response mNormal2Response =
- new Normal2Response.fromJson(response.data);
- if (mNormal2Response.code == Global.responseSuccessCode) {
- // Component.toast("上传成功!", 2);
- uploadImg.add(mNormal2Response.msg.toString());
- setState(() {});
- } else {
- Component.toast(mNormal2Response.msg.toString(), 0);
- }
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- return null;
- }
- } catch (e) {
- print(e);
- }
- }
- }
- Future<void> editChatDisease() async {
- if (age == "请选择年龄") {
- Component.toast("请选择患者年龄!", 0);
- return;
- }
- if (sex == "请选择性别") {
- Component.toast("请选择患者性别!", 0);
- return;
- }
- if (resourceController.text.isEmpty) {
- Component.toast("请填写病情资料!", 0);
- return;
- }
- if (uploadImg.length < 1) {
- Component.toast("请上传病历图片!", 0);
- return;
- }
- String uploadImgStr = uploadImg
- .sublist(1, uploadImg.length)
- .toString()
- .replaceAll("[", "")
- .replaceAll("]", "");
- print(uploadImgStr);
- int ageInt = int.parse(age);
- int sexInt = 0;
- if(sex == "女")
- sexInt = 1;
- var params = {
- 'name': Global.patient.data![Global.selectPatient].patientName.toString(),
- 'age': ageInt,
- 'sex': sexInt,
- 'docker': Global.doctor.data![Global.selectDoctor].nickName.toString(),
- 'resource': resourceController.text,
- 'patientId': Global.patient.data![Global.selectPatient].patientId,
- 'url': uploadImgStr,
- };
- print(params);
- Map<String, String> headers = {
- HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
- 'token': '${Global.token}',
- };
- var response = await http.put(
- Uri.parse(Global.BaseUrl + 'chat/editChatDisease'),
- body: jsonEncode(params),
- headers: headers);
- print(response.body.toString());
- if (response.statusCode == 200) {
- final jsonString = utf8.decode(response.bodyBytes);
- final jsonResponse = jsonDecode(jsonString);
- print(jsonString);
- NormalResponse mNormalResponse =
- new NormalResponse.fromJson(jsonResponse);
- if (mNormalResponse.code == Global.responseSuccessCode) {
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => ChatHome("")),
- );
- /*Navigator.pushAndRemoveUntil(
- context,
- MaterialPageRoute(builder: (context) => ChatHome()), (route) => false,
- );*/
- } else {
- Component.toast(mNormalResponse.msg.toString(), 0);
- }
- } else {
- Component.toast("出错了,请稍后再试!", 0);
- return null;
- }
- }
- selectItem(List list, int item) {
- showModalBottomSheet(
- context: context,
- builder: (BuildContext context) {
- return SingleChildScrollView(
- child: Container(
- width: double.infinity,
- height: list.length * 50,
- child: Column(
- children: List.generate(
- list.length,
- (index) => GestureDetector(
- onTap: () {
- setState(() {
- switch (item) {
- case 0:
- age = list[index].toString();
- break;
- case 1:
- sex = list[index];
- break;
- }
- });
- Navigator.pop(context);
- },
- child: Padding(
- padding: const EdgeInsets.all(10),
- child: Text(
- ' ${list[index]} ',
- style: TextStyle(fontSize: 18),
- ),
- ),
- ),
- ),
- ),
- ),
- );
- },
- );
- }
- }
|