LCOV - code coverage report
Current view: top level - lib/models - search.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 37 0.0 %
Date: 2024-10-28 21:12:34 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/widgets.dart';
       2             : import 'package:provider/provider.dart';
       3             : import 'package:cwtch/widgets/textfield.dart';
       4             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
       5             : import 'profile.dart';
       6             : import 'contact.dart';
       7             : import 'contactlist.dart';
       8             : 
       9             : class SearchResult {
      10             :   String searchID;
      11             :   int conversationIdentifier;
      12             :   int messageIndex;
      13           0 :   SearchResult({required this.searchID, required this.conversationIdentifier, required this.messageIndex});
      14             : }
      15             : 
      16             : class SearchState extends ChangeNotifier {
      17             :   bool _searchActive = false;
      18             :   int? _selectedSearchMessage;
      19             :   String _filter = "";
      20             :   String activeSearchID = "";
      21             :   List<SearchResult> activeSearchResults = List.empty(growable: true);
      22             : 
      23           0 :   SearchState();
      24             : 
      25             : 
      26           0 :   void newSearch(String searchID) {
      27           0 :     this.activeSearchID = searchID;
      28           0 :     this.activeSearchResults.clear();
      29           0 :     notifyListeners();
      30             :   }
      31             : 
      32           0 :   void handleSearchResult(String searchID, int conversationIdentifier, int messageIndex) {
      33           0 :     if (searchID == this.activeSearchID) {
      34           0 :       this.activeSearchResults.add(SearchResult(searchID: searchID, conversationIdentifier: conversationIdentifier, messageIndex: messageIndex));
      35           0 :       notifyListeners();
      36             :     }
      37             :   }
      38             : 
      39           0 :   int? get selectedSearchMessage => _selectedSearchMessage;
      40           0 :   set selectedSearchMessage(int? newVal) {
      41           0 :     this._selectedSearchMessage = newVal;
      42           0 :     notifyListeners();
      43             :   }
      44             : 
      45           0 :   bool get isFiltered => _filter != "";
      46           0 :   String get filter => _filter;
      47           0 :   set filter(String newVal) {
      48           0 :     _filter = newVal.toLowerCase();
      49           0 :     notifyListeners();
      50             :   }
      51             : 
      52           0 :   bool get searchActive => _searchActive;
      53           0 :   set searchActive(bool newVal) {
      54           0 :     this._searchActive = newVal;
      55           0 :     notifyListeners();
      56             :   }
      57             : 
      58           0 :   bool get searchOrFiltered {
      59           0 :     return this._filter != "" || this._searchActive == true;
      60             :   }
      61             : 
      62           0 :   void toggleSearch() {
      63           0 :     if (this.searchActive) {
      64           0 :       this.clearSearch();
      65             :     } else {
      66           0 :       this._filter = "";
      67           0 :       this.searchActive = true;
      68           0 :       notifyListeners();
      69             :     }
      70             :   }
      71             : 
      72           0 :   void clearSearch() {
      73           0 :     this._searchActive = false;
      74           0 :     this._selectedSearchMessage = null;
      75           0 :     this._filter = "";
      76           0 :     this.newSearch("");
      77           0 :     notifyListeners();
      78             :   }
      79             : }

Generated by: LCOV version 1.14