Delete a product from the database.

Now it's time to remove a product that we don't want anymore by clicking on that trash icon in listeview.

onPressed: () {
    setState(() {
        helper.deleteProduct(product.id);
    });
}),

So now if you try to delete any product it will be deleted with any problem.

and here is the final code for the home page again. compare it to what you have been written.

import 'package:flutter/material.dart';
import './update_product_page.dart';
import './view_product_page.dart';
import './add_product_page.dart';
import '../models/product.dart';
import '../services/dbhelper.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  DbHelper helper;
  @override
  void initState() {
    super.initState();
    helper = DbHelper();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Home Page"),
      ),
      body: FutureBuilder(
        future: helper.getProducts(),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (BuildContext context, int index) {
                Product product = Product.fromMap(snapshot.data[index]);
                return ListTile(
                  contentPadding: const EdgeInsets.all(16),
                  title:
                      Text("${product.name} - \$${(product.price).toString()}"),
                  subtitle: Text(product.description),
                  trailing: Column(
                    children: [
                      Expanded(
                        child: IconButton(
                            icon: Icon(
                              Icons.delete,
                              color: Colors.red,
                              size: 24,
                            ),
                            onPressed: () {
                              setState(() {
                                helper.deleteProduct(product.id);
                              });
                            }),
                      ),
                      Expanded(
                        child: IconButton(
                          icon: Icon(
                            Icons.edit,
                            color: Colors.blue,
                            size: 24,
                          ),
                          onPressed: () {
                            Navigator.of(context).push(
                              MaterialPageRoute(
                                builder: (context) => UpdateProductPage(),
                              ),
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                  onTap: () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (context) =>
                            ProductDetailsPage(product: product),
                      ),
                    );
                  },
                );
              },
            );
          } else {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add, color: Colors.white),
        onPressed: () {
          Navigator.of(context).push(
            MaterialPageRoute(
              builder: (context) => AddProductPage(),
            ),
          );
        },
      ),
    );
  }
}