Advertisement
amonnoris

connection_log.dart

Oct 5th, 2024 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.06 KB | Source Code | 0 0
  1. // lib/models/connection_log.dart
  2.  
  3. class ConnectionLog {
  4.   final String serverName;
  5.   final DateTime startTime;
  6.   Duration duration;
  7.   final int dataUploaded; // in bytes
  8.   final int dataDownloaded; // in bytes
  9.  
  10.   ConnectionLog({
  11.     required this.serverName,
  12.     required this.startTime,
  13.     required this.duration,
  14.     required this.dataUploaded,
  15.     required this.dataDownloaded,
  16.   });
  17.  
  18.   // Convert a ConnectionLog into a Map.
  19.   Map<String, dynamic> toJson() => {
  20.         'serverName': serverName,
  21.         'startTime': startTime.toIso8601String(),
  22.         'duration': duration.inSeconds,
  23.         'dataUploaded': dataUploaded,
  24.         'dataDownloaded': dataDownloaded,
  25.       };
  26.  
  27.   // Create a ConnectionLog from a Map.
  28.   factory ConnectionLog.fromJson(Map<String, dynamic> json) => ConnectionLog(
  29.         serverName: json['serverName'],
  30.         startTime: DateTime.parse(json['startTime']),
  31.         duration: Duration(seconds: json['duration']),
  32.         dataUploaded: json['dataUploaded'],
  33.         dataDownloaded: json['dataDownloaded'],
  34.       );
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement