Здравствуйте, столкнулся с проблемой что когда я пытаюсь подключиться к базе данных MongoDB этим кодом:
main.dart
import 'package:flutter/material.dart';
import 'package:meme_media/database/database.dart';
import 'package:meme_media/pages/home_page.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
home_page.dart
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
database.dart
// ignore_for_file: avoid_print, unnecessary_null_comparison
import 'package:mongo_dart/mongo_dart.dart' show Db, DbCollection;
class DBConnection {
static late DBConnection _instance;
late Db _db;
static getInstance() {
if (_instance == null) {
_instance = DBConnection();
}
return _instance;
}
Future<Db> getConnection() async {
try {
_db = Db(_getConnectionString());
await _db.open();
} catch (e) {
print(e);
}
return _db;
}
_getConnectionString() {
return "XXX";
}
closeConnection() {
_db.close();
}
}
Вылезает ошибка:
Код скриншотами(тут нет подсветки dart'a)