通话记录展示
This commit is contained in:
86
lib/common/channel/call_log_model.dart
Normal file
86
lib/common/channel/call_log_model.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// number : "18092171236"
|
||||
/// date : "2024-11-21 09:32:27"
|
||||
/// duration : 0
|
||||
/// type : 5
|
||||
/// name : gong
|
||||
|
||||
CallLogModel callLogModelFromJson(String str) =>
|
||||
CallLogModel.fromJson(json.decode(str));
|
||||
|
||||
String callLogModelToJson(CallLogModel data) => json.encode(data.toJson());
|
||||
|
||||
class CallLogModel {
|
||||
CallLogModel({
|
||||
String? number,
|
||||
String? date,
|
||||
num? duration,
|
||||
num? type,
|
||||
String? name,
|
||||
String? time,
|
||||
}) {
|
||||
_number = number;
|
||||
_date = date;
|
||||
_duration = duration;
|
||||
_type = type;
|
||||
_name = name;
|
||||
_time = time;
|
||||
}
|
||||
|
||||
CallLogModel.fromJson(dynamic json) {
|
||||
_number = json['number'];
|
||||
_date = json['date'];
|
||||
_duration = json['duration'];
|
||||
_type = json['type'];
|
||||
_name = json['name'];
|
||||
_time = json['time'];
|
||||
}
|
||||
|
||||
String? _number;
|
||||
String? _date;
|
||||
num? _duration;
|
||||
num? _type;
|
||||
String? _name;
|
||||
String? _time;
|
||||
|
||||
CallLogModel copyWith({
|
||||
String? number,
|
||||
String? date,
|
||||
num? duration,
|
||||
num? type,
|
||||
String? name,
|
||||
String? time,
|
||||
}) =>
|
||||
CallLogModel(
|
||||
number: number ?? _number,
|
||||
date: date ?? _date,
|
||||
duration: duration ?? _duration,
|
||||
type: type ?? _type,
|
||||
name: name ?? _name,
|
||||
time: time ?? _time,
|
||||
);
|
||||
|
||||
String? get number => _number;
|
||||
|
||||
String? get date => _date;
|
||||
|
||||
num? get duration => _duration;
|
||||
|
||||
num? get type => _type;
|
||||
|
||||
String? get name => _name;
|
||||
|
||||
String? get time => _time;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map['number'] = _number;
|
||||
map['date'] = _date;
|
||||
map['duration'] = _duration;
|
||||
map['type'] = _type;
|
||||
map['name'] = _name;
|
||||
map['time'] = _time;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../manager/event_manager.dart';
|
||||
import 'call_log_model.dart';
|
||||
import 'names.dart';
|
||||
|
||||
class MyEventChannel {
|
||||
@@ -13,13 +17,19 @@ class MyEventChannel {
|
||||
channel.receiveBroadcastStream().listen((Object? o) {
|
||||
yjPrint("onGetCallLogResult");
|
||||
yjPrint(o);
|
||||
// AlipayPayResultEvent event = AlipayPayResultEvent();
|
||||
// if (o is int) {
|
||||
// event.resultStatus = o;
|
||||
// } else {
|
||||
// event.resultStatus = int.parse(o as String);
|
||||
// }
|
||||
// EventManager.postEvent(event);
|
||||
GetCallLogEvent event = GetCallLogEvent();
|
||||
if (o is String) {
|
||||
event.isSuccess = true;
|
||||
List<dynamic> list = json.decode(o);
|
||||
List<CallLogModel> callLogs = [];
|
||||
for (var item in list) {
|
||||
callLogs.add(CallLogModel.fromJson(item));
|
||||
}
|
||||
event.callLogs = callLogs.reversed.toList();
|
||||
} else {
|
||||
event.isSuccess = false;
|
||||
}
|
||||
EventManager.postEvent(event);
|
||||
}, onError: (Object error) {
|
||||
yjPrint("onGetCallLogResult error");
|
||||
});
|
||||
|
||||
54
lib/common/manager/event_manager.dart
Normal file
54
lib/common/manager/event_manager.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cashier_reserve/common/channel/call_log_model.dart';
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
|
||||
|
||||
class EventManager {
|
||||
static EventBus? _eventBus;
|
||||
|
||||
static final Map<dynamic, List<StreamSubscription>> _eventMap = {};
|
||||
|
||||
static EventBus? get eventBus => getEventBus();
|
||||
|
||||
static EventBus? getEventBus() {
|
||||
_eventBus ??= EventBus();
|
||||
return _eventBus;
|
||||
}
|
||||
|
||||
static void postEvent(MyEvent event) {
|
||||
getEventBus()!.fire(event);
|
||||
}
|
||||
|
||||
static void addListener<T>(dynamic widget, void Function(T event) onData) {
|
||||
StreamSubscription event = EventManager.eventBus!.on<T>().listen((T e) {
|
||||
onData(e);
|
||||
});
|
||||
List<StreamSubscription>? list = _eventMap[widget];
|
||||
list ??= [];
|
||||
list.add(event);
|
||||
_eventMap[widget] = list;
|
||||
}
|
||||
|
||||
static void cancelListener(dynamic widget) {
|
||||
List<StreamSubscription>? list = _eventMap[widget];
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
for (var event in list) {
|
||||
event.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyEvent {
|
||||
String name = '';
|
||||
}
|
||||
|
||||
class GetCallLogEvent extends MyEvent {
|
||||
List<CallLogModel> callLogs;
|
||||
bool isLoadMore = false;
|
||||
bool isSuccess = false;
|
||||
|
||||
GetCallLogEvent({this.callLogs = const [], this.isLoadMore = false, this.isSuccess = false});
|
||||
}
|
||||
Reference in New Issue
Block a user