import 'package:flutter/foundation.dart';
import 'package:postgres/postgres.dart';
PostgreSQLConnection(String s, int i, String t, {required String username, required String password}) {}
void main() async {
// Create an instance of PostgreSQLConnection with connection parameters
final connection = PostgreSQLConnection( '91.225.104.133',
5432,// Port number
'homeservice',
username: 'homeservice',
password: 'SrVEJGj2DNQo', );
try {
// Open the connection
await connection.open();
print('Connected to PostgreSQL database!');
// Perform database operations here
// For example, execute a query
final results = await connection.query('SELECT * FROM servicemodels');
print('Query results: $results');
} catch (e) {
print('Error connecting to database: $e');
} finally {
// Always remember to close the connection when done
await connection.close();
print('Connection closed.'); } }
this is the code i wrote for the connection between dart program and postgresql but it keeps giving the same error since the beginning :
Connecting to VM Service at ws://127.0.0.1:51948/EqB2XheM_3U=/ws
Error connecting to database: NoSuchMethodError: 'open'
Dynamic call of null.
Receiver: null
Arguments: []
What should i do? its due tomorrow and i have to commit the db.dart file which i tried to write to connection on into the original file.
New contributor
oguzyucel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.