'How can I connect my flutter project to postgresql database? (ubuntu 20.04)

I tried using flutter dependency "postgres" but my connection is refused. I also don't know how to start my postgresql server on ubuntu or call it using a restapi.



Solution 1:[1]

Hay ,, you want to connect flutter app to postgresql right? Firstly you can't use flutter in web mod to postgresql

1-> Create a user in postgresql, something like username flutter password flutter, give permission for that user to read the table. easy commands GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO flutter; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO flutter;

2-> Configure your postgresql database for created user (eg.flutter) https://blog.logrocket.com/setting-up-a-remote-postgres-database-server-on-ubuntu-18-04/ check that link to configure postgresql.conf and pg_hba.conf after that test connect by psql command ->psql -h (host) -d (database) -U (user) host databasename flutter 0.0.0.0/0 md5 inhba listen_addresses = '*' inconfig

3-> Add fire wall rule,, for windows netsh advfirewall firewall add rule name="postgresin" dir=in action=allow protocol=TCP localport=8069 netsh advfirewall firewall add rule name="postgresout" dir=out action=allow protocol=TCP localport=8069

4->https://pub.dev/packages/postgres try

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OakarminSTBM