From 74274bb8ce9e54899c65e30772997c907c4baa55 Mon Sep 17 00:00:00 2001
From: JarodJeffery <JarodJeffery@gmail.com>
Date: Sun, 22 Sep 2024 15:07:14 +0200
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Introduce=20new=20features.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 beakpeek/lib/Controller/DB/life_list_provider.dart | 7 +++++++
 beakpeek/lib/Model/bird_page_functions.dart        | 7 +++++++
 beakpeek/lib/View/Bird/bird_page.dart              | 1 +
 3 files changed, 15 insertions(+)

diff --git a/beakpeek/lib/Controller/DB/life_list_provider.dart b/beakpeek/lib/Controller/DB/life_list_provider.dart
index d8ee2920..04db5cac 100644
--- a/beakpeek/lib/Controller/DB/life_list_provider.dart
+++ b/beakpeek/lib/Controller/DB/life_list_provider.dart
@@ -302,4 +302,11 @@ class LifeListProvider {
       },
     ).toList();
   }
+
+  Future<List<Map<String, Object?>>> getBirdInByID(int id) async {
+    final db = await instance.database;
+    final List<Map<String, Object?>> birdMap =
+        await db.query('allBirds', where: 'id = ?', whereArgs: [id]);
+    return birdMap;
+  }
 }
diff --git a/beakpeek/lib/Model/bird_page_functions.dart b/beakpeek/lib/Model/bird_page_functions.dart
index 5fa5fdbf..e4717da3 100644
--- a/beakpeek/lib/Model/bird_page_functions.dart
+++ b/beakpeek/lib/Model/bird_page_functions.dart
@@ -1,6 +1,7 @@
 // api_service.dart
 
 import 'dart:convert';
+import 'package:beakpeek/Controller/DB/life_list_provider.dart';
 import 'package:http/http.dart' as http;
 
 class ApiService {
@@ -14,6 +15,7 @@ class ApiService {
     );
 
     if (response.statusCode == 200) {
+      print(json.decode(response.body));
       return json.decode(response.body);
     } else {
       // Handle the error
@@ -22,4 +24,9 @@ class ApiService {
       return null;
     }
   }
+
+  Future<List<Map<String, Object?>>> fetchBirdInfoOffline(
+      LifeListProvider lifeList, int id) async {
+    return await lifeList.getBirdInByID(id);
+  }
 }
diff --git a/beakpeek/lib/View/Bird/bird_page.dart b/beakpeek/lib/View/Bird/bird_page.dart
index 0264daa5..3722ba8f 100644
--- a/beakpeek/lib/View/Bird/bird_page.dart
+++ b/beakpeek/lib/View/Bird/bird_page.dart
@@ -44,6 +44,7 @@ class _BirdPageState extends State<BirdPage> {
     super.initState();
     birdFuture =
         ApiService().fetchBirdInfo(widget.commonGroup, widget.commonSpecies);
+    ApiService().fetchBirdInfoOffline(lifeList, widget.id);
   }
 
   void addToLifeList() {