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-12-02 20:23:46 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           0 :   void newSearch(String searchID) {
      26           0 :     this.activeSearchID = searchID;
      27           0 :     this.activeSearchResults.clear();
      28           0 :     notifyListeners();
      29             :   }
      30             : 
      31           0 :   void handleSearchResult(String searchID, int conversationIdentifier, int messageIndex) {
      32           0 :     if (searchID == this.activeSearchID) {
      33           0 :       this.activeSearchResults.add(SearchResult(searchID: searchID, conversationIdentifier: conversationIdentifier, messageIndex: messageIndex));
      34           0 :       notifyListeners();
      35             :     }
      36             :   }
      37             : 
      38           0 :   int? get selectedSearchMessage => _selectedSearchMessage;
      39           0 :   set selectedSearchMessage(int? newVal) {
      40           0 :     this._selectedSearchMessage = newVal;
      41           0 :     notifyListeners();
      42             :   }
      43             : 
      44           0 :   bool get isFiltered => _filter != "";
      45           0 :   String get filter => _filter;
      46           0 :   set filter(String newVal) {
      47           0 :     _filter = newVal.toLowerCase();
      48           0 :     notifyListeners();
      49             :   }
      50             : 
      51           0 :   bool get searchActive => _searchActive;
      52           0 :   set searchActive(bool newVal) {
      53           0 :     this._searchActive = newVal;
      54           0 :     notifyListeners();
      55             :   }
      56             : 
      57           0 :   bool get searchOrFiltered {
      58           0 :     return this._filter != "" || this._searchActive == true;
      59             :   }
      60             : 
      61           0 :   void toggleSearch() {
      62           0 :     if (this.searchActive) {
      63           0 :       this.clearSearch();
      64             :     } else {
      65           0 :       this._filter = "";
      66           0 :       this.searchActive = true;
      67           0 :       notifyListeners();
      68             :     }
      69             :   }
      70             : 
      71           0 :   void clearSearch() {
      72           0 :     this._searchActive = false;
      73           0 :     this._selectedSearchMessage = null;
      74           0 :     this._filter = "";
      75           0 :     this.newSearch("");
      76           0 :     notifyListeners();
      77             :   }
      78             : }

Generated by: LCOV version 1.14