Coffee & Code - Algolia Search & Crashlytics Integration

Coffee & Code - Algolia Search & Crashlytics Integration

Implementing Algolia full-text search, book completion tracking, and Firebase Crashlytics in the Quote Keeper app.


Sample Image
Cappuccino from Hija Mía in Medellín, Colombia.

There are three key components that I have made progress on for the app this sprint.

1. Full text search, using Algolia and Firebase Extensions.

Using this popular search-as-a-service platform, Algolia allows me to integrate fast, accurate, and customizable search features into the app. The process is made even smoother by syncing with my Firestore database whenever a new document is modified. This is all possible with Firebase Extensions, pre-packaged solutions that integrate other services into my Firebase project.

Sample Image
Using Algolia search API.
/// Query for books based on search text and match the current uid.
void _performSearch() async {
  final SearchForHits queryHits = SearchForHits (
    indexName: 'books',
    query: searchText,
    // Return 5 results per query.
    hitsPerPage: 5,
    facetFilters: ['uid:$_uid'],
 
  // Execute the search request.
  final SearchResponse responseHits = await _client.searchIndex (request: queryHits);
  // Convert hits to list of book search results.
  _bookSearchResults = responseHits.hits
    .map(
      (hit) => BookModel(
        id: hit['id'],
        quote: hit['quote'],
        title: hit['title'],
        author: hit ['author'],
        imgPath: hit ['imgPath'],
        hidden: hit['hidden'],
        complete: hit['complete'],
        uid: hit['uid'],
        created: DateTime.from MillisecondsSinceEpoch (hit['created']),
        modified: DateTime.fromMillisecondsSinceEpoch (hit ['modified']),
      )
    )
    .toList();
  // Update state.
  notifyListeners();
}

2. Book Completed Flag

Once users finish reading a book, they can mark it with a green checkmark. By toggling this boolean flag on or off, users can keep track of the books they’ve read and those they still need to finish.

Sample Image
Completed flag on each book model.
if (book.complete) ... [  const Padding (
    padding: EdgeInsets.symmetric (horizontal: 4.0),
    child: Icon(
      Icons.check,
      color: Colors.blue,
      size: 15,
    )
  )
]

3. Crashlytics

By using this real-time crash reporting tool, it helps monitor any issues that could harm the app’s overall quality. It provides detailed crash reports, helping me prioritise and solve these problems, thus improving the app’s stability and user satisfaction.

Sample Image
My Crashlytics dashboard in Firebase.
/// Setup crashlytics.
Future<void> _setupCrashlytics() async {
  final crashlytics = FirebaseCrashlytics. instance;
  await crashlytics.setCrashlytics CollectionEnabled(true);
  FlutterError.onError = (errorDetails) async {
    await crashlytics. record FlutterError(errorDetails);
  };
  // Pass all uncaught asynchronous errors that aren't
  // handled by the Flutter framework to Crashlytics.
  PlatformDispatcher.instance.onError = (error, stack) {
    crashlytics.recordError(error, stack, fatal: true);
    return true;
  };
}

Also, the app is now available on iOS and Android! Any feedback is appreciated.


Related posts
Coffee & Code - Firestore Sorting & Toast Messages

Coffee & Code - Firestore Sorting & Toast Messages

Read more
Coffee & Code - Rewriting My App, GetX to Riverpod

Coffee & Code - Rewriting My App, GetX to Riverpod

Read more
Coffee & Code - Book Quote App Firebase Migration & Authentication

Coffee & Code - Book Quote App Firebase Migration & Authentication

Read more
Coffee & Code - Deploying My Jaspr Site on Globe

Coffee & Code - Deploying My Jaspr Site on Globe

Read more