-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Rexsunon/feat/no-ref/search-and-filter
feat: create and implement network filter functionality
- Loading branch information
Showing
6 changed files
with
201 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/src/presentation/notifier/network_record_notifier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:logman/src/models/models.dart'; | ||
import 'package:logman/src/presentation/pages/pages.dart'; | ||
|
||
class NetworkRecordNotifier extends ValueNotifier<List<NetworkLogmanRecord>> { | ||
NetworkRecordNotifier(List<NetworkLogmanRecord> initialValue) | ||
: super(initialValue) { | ||
_originalNetworkRecords = List.from(initialValue); | ||
} | ||
|
||
late final List<NetworkLogmanRecord> _originalNetworkRecords; | ||
|
||
void filterNetworkRecords(NetworkStatus status) { | ||
value = _originalNetworkRecords.where((networkRecord) { | ||
switch (status) { | ||
case NetworkStatus.success: | ||
return _isSuccessStatusCode(networkRecord); | ||
case NetworkStatus.error: | ||
return _isErrorStatusCode(networkRecord); | ||
case NetworkStatus.all: | ||
default: | ||
return true; | ||
} | ||
}).toList(); | ||
notifyListeners(); | ||
} | ||
|
||
bool _isSuccessStatusCode(NetworkLogmanRecord record) { | ||
final statusCode = record.response?.statusCode; | ||
return statusCode != null && statusCode >= 200 && statusCode < 300; | ||
} | ||
|
||
bool _isErrorStatusCode(NetworkLogmanRecord record) { | ||
final statusCode = record.response?.statusCode; | ||
return statusCode != null && (statusCode >= 400 && statusCode <= 500) || | ||
statusCode == 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'network_record_notifier.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:logman/logman.dart'; | ||
import 'package:logman/src/presentation/notifier/notifier.dart'; | ||
import 'package:logman/src/presentation/presentation.dart'; | ||
|
||
class NetworkRecordsPage extends StatelessWidget { | ||
final List<LogmanRecord> records; | ||
final NetworkRecordNotifier networkRecordNotifier; | ||
|
||
const NetworkRecordsPage({super.key, required this.records}); | ||
const NetworkRecordsPage({super.key, required this.networkRecordNotifier}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final simpleRecords = List<LogmanRecord>.from(records) | ||
..retainWhere( | ||
(element) => element is NetworkLogmanRecord, | ||
); | ||
return ValueListenableBuilder<List<NetworkLogmanRecord>>( | ||
valueListenable: networkRecordNotifier, | ||
builder: (context, networkRecords, child) { | ||
if (networkRecords.isEmpty) { | ||
return const Center( | ||
child: Text('No Network calls recorded yet!'), | ||
); | ||
} | ||
|
||
if (simpleRecords.isEmpty) { | ||
return const Center( | ||
child: Text('No Network calls recorded yet!'), | ||
); | ||
} | ||
|
||
return ListView.separated( | ||
itemCount: simpleRecords.length, | ||
itemBuilder: (context, index) { | ||
final record = simpleRecords[index] as NetworkLogmanRecord; | ||
return NetworkRecordItem(record: record); | ||
return ListView.separated( | ||
itemCount: networkRecords.length, | ||
itemBuilder: (context, index) { | ||
final networkRecord = networkRecords[index]; | ||
return NetworkRecordItem(record: networkRecord); | ||
}, | ||
separatorBuilder: (context, index) => const CustomDivider(), | ||
); | ||
}, | ||
separatorBuilder: (context, index) => const CustomDivider(), | ||
); | ||
} | ||
} |