title: how to save favorite items in locale storage device using provider & sqflite database flutter
body: <p>hi guys i have problem here, i use provider package to add favorite items in favorite page, is working fine, so when i restart application favorite items is Disappear i want to keep items in locale storage, anyone help me how to solve this problem using sqlite database.</p>
  <p>I will be grateful for solving this problem</p>
  <p>this is favorite model using provider</p>
  <pre><code>class FavoriteItem {
  
     String id;
     String image;
     String title;
     String typeFood;
     String timeFood;
     double price;
  
     FavoriteItem(this.id, this.image, this.title, this.typeFood, this.timeFood,
        this.price);
  
  
  }
  
  class Favorite with ChangeNotifier{
  
  
    Map&lt;String, FavoriteItem&gt; _items = {};
  
    Map&lt;String, FavoriteItem&gt; get items {
      return {..._items};
    }
  
    int get itemCount {
      return _items.length;
    }
  
  
    void addFavoriteItem(String foodId, String foodImage, String foodTitle, String foodType, String foodTime, double foodPrice){
  
      if(_items.containsKey(foodId)){
  
        _items.update(foodId, (existingFavoriteItem) =&gt;
  
            FavoriteItem(
                 DateTime.now().toString(),
                 existingFavoriteItem.image,
                 existingFavoriteItem.title,
                 existingFavoriteItem.typeFood,
                 existingFavoriteItem.timeFood,
                 existingFavoriteItem.price
            )
        );
  
      }else {
         _items.putIfAbsent(
            foodId,
                () =&gt;
                    FavoriteItem(
  
               DateTime.now().toString(),
               foodImage,
               foodTitle,
               foodType,
               foodTime,
               foodPrice,
  
            ));
      }
  
      notifyListeners();
    }
  
   
  
       void removeItem(String id) {
          _items.remove(id);
          notifyListeners();
        }
      
      
        void clear() {
          _items = {};
          notifyListeners();
        }
      }
  </code></pre>
  <p>this is favorite page</p>
  <pre><code>class FavoritePage extends StatefulWidget {
    @override
    _FavoritePageState createState() =&gt; _FavoritePageState();
  }
  
  class _FavoritePageState extends State&lt;FavoritePage&gt; {
  
  
    @override
    Widget build(BuildContext context) {
  
      final favorite = Provider.of&lt;Favorite&gt;(context);
  
      return Scaffold(
          backgroundColor: Color(0xffFFFAEE),
          body: SafeArea(
            child: Column(
              children: &lt;Widget&gt;[
                Padding(
                  padding: const EdgeInsets.all(15),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: &lt;Widget&gt;[
                      Text(
                        &quot;Your Favorite Foods&quot;,
                        style: TextStyle(
                            fontSize: 20,
                            fontWeight: FontWeight.bold,
                            color: Color(0xff544646)
                        ),
                      ),
                      Row(
                        children: &lt;Widget&gt;[
                          Tooltip(
                            message: &quot;Delete All&quot;,
                            textStyle: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: Color(0xffFFDB84)
                            ),
                            decoration: BoxDecoration(
                                color: Colors.black,
                                borderRadius: BorderRadius.circular(6)
                            ),
                            child: GestureDetector(
                              onTap: (){
                                showDialog(
                                    context: context,
                                    builder: (BuildContext context) =&gt; AlertDialog(
                                      title: Text(
                                        &quot;Do you want delete this food?&quot;,
                                        style: TextStyle(
                                            fontSize: 18,
                                            color: Color(0xff544646),
                                            fontWeight: FontWeight.w600
                                        ),
                                      ),
                                      shape: RoundedRectangleBorder(
                                          borderRadius: BorderRadius.all(Radius.circular(15))
                                      ),
                                      backgroundColor: Color(0xffFFFAEE),
                                      actions: &lt;Widget&gt;[
                                        FlatButton(
                                            onPressed: (){
                                              Navigator.of(context).pop(false);
                                            },
                                            child: Text(
                                              &quot;No&quot;,
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontWeight: FontWeight.bold
                                              ),
                                            )
                                        ),
                                        FlatButton(
                                            onPressed: (){
                                              Navigator.of(context).pop(true);
                                              Provider.of&lt;Favorite&gt;(context, listen: false).clear();
                                            },
                                            child: Text(
                                              &quot;Yes&quot;,
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontWeight: FontWeight.bold
                                              ),
                                            )
                                        )
                                      ],
                                    )
                                );
  
                              },
                              child: Container(
                                height: 40,
                                width: 40,
                                decoration: BoxDecoration(
                                    color: Color(0xffFFDB84),
                                    borderRadius: BorderRadius.circular(100)
                                ),
                                child: Icon(
                                  Icons_BottomBar.delete,
                                  size: 22,
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                Expanded(
                  // If favorite items is empty show image and text &quot; favorite is empty &quot;
                  child: favorite.items.isEmpty
                      ? Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: &lt;Widget&gt;[
                      Container(
                        height: 260,
                          width: 260,
                          child: SvgPicture.asset(
                              favorite_empty
                          )),
                      Text(
                        &quot;Favorite is Empty&quot;,
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      )
                    ],
                  )
  
                  // else
                      :ListView.builder(
                      itemCount: favorite.items.length,
                      itemBuilder: (context, index) =&gt;
                      FavoriteCardItem(
                        favorite.items.values.toList()[index].id,
                        favorite.items.keys.toList()[index],
                        favorite.items.values.toList()[index].image,
                        favorite.items.values.toList()[index].title,
                        favorite.items.values.toList()[index].typeFood,
                        favorite.items.values.toList()[index].timeFood,
                        favorite.items.values.toList()[index].price,
                      )
                  ),
                ),
                SizedBox(
                  height: 70,
                ),
              ],
            ),
          )
  
      );
    }
  }
  </code></pre>
  <p>this is favorite icon when click add favorite to favorite page</p>
  <pre><code>Padding(
                              padding: const EdgeInsets.only(right: 10),
                              child: GestureDetector(
                                onTap: () async {
                                  setState(() {
                                    isPressed = true;
                                  });
                                  Scaffold.of(context).showSnackBar(SnackBar(
                                    backgroundColor: Colors.black,
                                    content: Text(
                                      &quot;Item Added to Favorite&quot;,
                                      style: TextStyle(
                                          color: Color(0xffFFDB84)
                                      ),
                                    ),
                                    duration: Duration(seconds: 3),
                                  ));
                                 favorite.addFavoriteItem(
                                     loadFood.id,
                                     loadFood.image,
                                     loadFood.title,
                                     loadFood.typeFood,
                                     loadFood.timeFood,
                                     loadFood.price
                                 );
  
                                 // await helper.createFavorite(favorite.favoriteItem);
  
                                },
                                child: Container(
                                  height: 35,
                                  width: 35,
                                  decoration: BoxDecoration(
                                      borderRadius: BorderRadius.circular(20),
                                      color: Color(0xffFFDB84)
                                  ),
                                  // active favorite icon when clicked
                                  child: (isPressed)
                                      ?Icon(Icons.favorite, size: 20,color: Color(0xffff124d))
                                      :Icon(Icons.favorite_border, size: 20,color: Color(0xffff124d)),
                                ),
                              ),
                            ),
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DE7pi.png" rel="nofollow noreferrer">here is screenshot about favorite page</a></p>