|
|
|
@ -1,17 +1,79 @@ |
|
|
|
import 'package:common_utils/common_utils.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
|
|
|
|
|
import '../../../data/services/db/sqflite_api.dart'; |
|
|
|
import '../controllers/meeting_details_controller.dart'; |
|
|
|
|
|
|
|
class SpeakerAllBottomSheet extends GetView<MeetingDetailsController> { |
|
|
|
class SpeakerAllBottomSheet extends StatefulWidget { |
|
|
|
const SpeakerAllBottomSheet({super.key}); |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
List dataList = _getDataList(); |
|
|
|
State<SpeakerAllBottomSheet> createState() => _SpeakerAllBottomSheetState(); |
|
|
|
} |
|
|
|
|
|
|
|
class _SpeakerAllBottomSheetState extends State<SpeakerAllBottomSheet> { |
|
|
|
final _controller = Get.find<MeetingDetailsController>(); |
|
|
|
final GetStorage _storage = GetStorage(); |
|
|
|
|
|
|
|
List _dataList = []; |
|
|
|
|
|
|
|
List _historySpeakerList = []; |
|
|
|
List _speakerList = []; |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
_getSpeakerList(); |
|
|
|
} |
|
|
|
|
|
|
|
void _getSpeakerList() { |
|
|
|
_historySpeakerList = _storage.read("speaker_list") ?? []; |
|
|
|
_speakerList = List.from(_historySpeakerList); |
|
|
|
List textList = _controller.textList; |
|
|
|
List dataList = []; |
|
|
|
for (var item in textList) { |
|
|
|
String speaker = item['speaker']; |
|
|
|
Map? foundElement = dataList.firstWhere( |
|
|
|
(element) => element['speaker'] == speaker, |
|
|
|
orElse: () => null, |
|
|
|
); |
|
|
|
if (foundElement != null) { |
|
|
|
int time = item['endtime'] - item['starttime']; |
|
|
|
foundElement['totaltime'] = foundElement['totaltime'] + time; |
|
|
|
if (!foundElement['isOmit']) { |
|
|
|
if (foundElement['list'].length < 2) { |
|
|
|
foundElement['list'].add(Map.from(item)); |
|
|
|
} else { |
|
|
|
foundElement['isOmit'] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
dataList.add({ |
|
|
|
'speaker': speaker, |
|
|
|
'speakerText': TextEditingController(), |
|
|
|
'isShow': false, |
|
|
|
'totaltime': item['endtime'] - item['starttime'], |
|
|
|
'isOmit': false, |
|
|
|
'list': [Map.from(item)], |
|
|
|
}); |
|
|
|
} |
|
|
|
if (speaker.isNotEmpty && |
|
|
|
!RegExp(r'^Speaker \d+$').hasMatch(speaker) && |
|
|
|
!_speakerList.contains(speaker)) { |
|
|
|
_speakerList.add(speaker); |
|
|
|
} |
|
|
|
} |
|
|
|
setState(() { |
|
|
|
_dataList = dataList; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Padding( |
|
|
|
padding: EdgeInsets.only( |
|
|
|
left: 12.w, |
|
|
|
@ -63,11 +125,10 @@ class SpeakerAllBottomSheet extends GetView<MeetingDetailsController> { |
|
|
|
1.sh - 240.w - MediaQuery.of(context).viewInsets.bottom, |
|
|
|
), |
|
|
|
child: ListView.builder( |
|
|
|
itemCount: dataList.length, |
|
|
|
itemCount: _dataList.length, |
|
|
|
shrinkWrap: true, |
|
|
|
itemBuilder: (BuildContext context, int index) { |
|
|
|
TextEditingController textController = TextEditingController(); |
|
|
|
Map item = dataList[index]; |
|
|
|
Map item = _dataList[index]; |
|
|
|
return Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
@ -76,34 +137,107 @@ class SpeakerAllBottomSheet extends GetView<MeetingDetailsController> { |
|
|
|
alignment: Alignment.center, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
borderRadius: BorderRadius.circular(12.r), |
|
|
|
borderRadius: item['isShow'] && _speakerList.isNotEmpty |
|
|
|
? BorderRadius.vertical( |
|
|
|
top: Radius.circular(12.r), |
|
|
|
) |
|
|
|
: BorderRadius.circular(12.r), |
|
|
|
), |
|
|
|
child: TextField( |
|
|
|
controller: textController, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: Colors.black87, |
|
|
|
letterSpacing: 0, |
|
|
|
height: 1.4, |
|
|
|
), |
|
|
|
decoration: InputDecoration( |
|
|
|
hintText: item['speaker'], |
|
|
|
hintStyle: TextStyle( |
|
|
|
child: Focus( |
|
|
|
onFocusChange: (bool hasFocus) { |
|
|
|
item['isShow'] = hasFocus; |
|
|
|
}, |
|
|
|
child: TextField( |
|
|
|
controller: item['speakerText'], |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: Colors.grey[400], |
|
|
|
color: Colors.black87, |
|
|
|
letterSpacing: 0, |
|
|
|
height: 1.4, |
|
|
|
), |
|
|
|
isDense: true, |
|
|
|
fillColor: Colors.transparent, |
|
|
|
border: InputBorder.none, |
|
|
|
contentPadding: EdgeInsets.symmetric( |
|
|
|
horizontal: 10.w, |
|
|
|
vertical: 12.w, |
|
|
|
decoration: InputDecoration( |
|
|
|
hintText: item['speaker'], |
|
|
|
hintStyle: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: Colors.grey[400], |
|
|
|
letterSpacing: 0, |
|
|
|
height: 1.4, |
|
|
|
), |
|
|
|
isDense: true, |
|
|
|
fillColor: Colors.transparent, |
|
|
|
border: InputBorder.none, |
|
|
|
contentPadding: EdgeInsets.symmetric( |
|
|
|
horizontal: 10.w, |
|
|
|
vertical: 12.w, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
if (item['isShow'] && _speakerList.isNotEmpty) |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.only(left: 10.w), |
|
|
|
clipBehavior: Clip.hardEdge, |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
borderRadius: BorderRadius.vertical( |
|
|
|
bottom: Radius.circular(12.r), |
|
|
|
), |
|
|
|
border: Border( |
|
|
|
top: BorderSide( |
|
|
|
width: 1, |
|
|
|
color: Colors.grey[300]!, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Padding( |
|
|
|
padding: EdgeInsets.only(top: 10.w, bottom: 5.w), |
|
|
|
child: Text( |
|
|
|
'最近使用过的名称', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 12.sp, |
|
|
|
color: Colors.grey[600]!, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
Container( |
|
|
|
constraints: BoxConstraints( |
|
|
|
maxHeight: 150.h, |
|
|
|
), |
|
|
|
child: ListView.builder( |
|
|
|
itemCount: _speakerList.length, |
|
|
|
shrinkWrap: true, |
|
|
|
itemBuilder: (BuildContext context, int idx) { |
|
|
|
return GestureDetector( |
|
|
|
onTap: () { |
|
|
|
item['speakerText'].text = |
|
|
|
_speakerList[idx]; |
|
|
|
FocusScope.of(context).unfocus(); |
|
|
|
}, |
|
|
|
behavior: HitTestBehavior.translucent, |
|
|
|
child: SizedBox( |
|
|
|
height: 42.w, |
|
|
|
child: Align( |
|
|
|
alignment: Alignment.centerLeft, |
|
|
|
child: Text( |
|
|
|
_speakerList[idx], |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.sp, |
|
|
|
color: Colors.black87, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
Padding( |
|
|
|
padding: EdgeInsets.symmetric( |
|
|
|
horizontal: 10.w, |
|
|
|
@ -271,7 +405,7 @@ class SpeakerAllBottomSheet extends GetView<MeetingDetailsController> { |
|
|
|
10.horizontalSpace, |
|
|
|
Expanded( |
|
|
|
child: GestureDetector( |
|
|
|
onTap: () {}, |
|
|
|
onTap: _save, |
|
|
|
child: Container( |
|
|
|
height: 48.w, |
|
|
|
alignment: Alignment.center, |
|
|
|
@ -321,33 +455,43 @@ class SpeakerAllBottomSheet extends GetView<MeetingDetailsController> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
List _getDataList() { |
|
|
|
List textList = controller.textList; |
|
|
|
List dataList = []; |
|
|
|
for (var item in textList) { |
|
|
|
Map? foundElement = dataList.firstWhere( |
|
|
|
(element) => element['speaker'] == item['speaker'], |
|
|
|
orElse: () => null, |
|
|
|
); |
|
|
|
if (foundElement != null) { |
|
|
|
int time = item['endtime'] - item['starttime']; |
|
|
|
foundElement['totaltime'] = foundElement['totaltime'] + time; |
|
|
|
if (!foundElement['isOmit']) { |
|
|
|
if (foundElement['list'].length < 2) { |
|
|
|
foundElement['list'].add(Map.from(item)); |
|
|
|
} else { |
|
|
|
foundElement['isOmit'] = true; |
|
|
|
void _save() async { |
|
|
|
EasyLoading.show(); |
|
|
|
List textList = _controller.textList; |
|
|
|
List newTextList = []; |
|
|
|
List editSpeakerList = []; |
|
|
|
String personnel = ''; |
|
|
|
for (var element in textList) { |
|
|
|
final dataMap = Map<String, dynamic>.from(element); |
|
|
|
for (var data in _dataList) { |
|
|
|
String speaker = data['speakerText'].text; |
|
|
|
if (speaker.isNotEmpty && speaker != data['speaker']) { |
|
|
|
if (dataMap['speaker'] == data['speaker']) { |
|
|
|
dataMap['speaker'] = speaker; |
|
|
|
editSpeakerList.add({ |
|
|
|
'id': dataMap['id'], |
|
|
|
'speaker': dataMap['speaker'], |
|
|
|
}); |
|
|
|
} |
|
|
|
if (!RegExp(r'^Speaker \d+$').hasMatch(speaker) && |
|
|
|
!_historySpeakerList.contains(speaker)) { |
|
|
|
_historySpeakerList.insert(0, speaker); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
dataList.add({ |
|
|
|
'speaker': item['speaker'], |
|
|
|
'totaltime': item['endtime'] - item['starttime'], |
|
|
|
'isOmit': false, |
|
|
|
'list': [Map.from(item)], |
|
|
|
}); |
|
|
|
} |
|
|
|
if (!personnel.contains(dataMap['speaker'])) { |
|
|
|
personnel += '[${dataMap['speaker']}] '; |
|
|
|
} |
|
|
|
newTextList.add(dataMap); |
|
|
|
} |
|
|
|
var result = await SqfliteApi.editMeetingSpeaker(editSpeakerList); |
|
|
|
if (result != null) { |
|
|
|
_controller.textList.value = newTextList; |
|
|
|
SqfliteApi.editMeeting(_controller.id, {'personnel': personnel}); |
|
|
|
_controller.meetingDetails.value.personnel = personnel; |
|
|
|
_storage.write("speaker_list", _historySpeakerList); |
|
|
|
Get.back(); |
|
|
|
} |
|
|
|
return dataList; |
|
|
|
EasyLoading.dismiss(); |
|
|
|
} |
|
|
|
} |
|
|
|
|