”’我尝试使用颤振应用程序连接到 Mongodb 数据库并且它正在抛出证书错误,我也尝试添加 MyHttpOverrides 但没有修复。错误是=>“HandshakeException(HandshakeException:客户端握手错误(操作系统错误:CERTIFICATE_VERIFY_FAILED: 无法获取本地颁发者证书(handshake.cc:393)))”
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:projectv/routes/routes.dart';
import 'package:projectv/screens/home.dart';
import 'package:projectv/screens/property_detail.dart';
import 'package:projectv/utitlity/mongo_db.dart';
import './screens/agent.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = MyHttpOverrides();
await MongoDbConnection.dbConnect();
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Color.fromARGB(255, 83, 167, 236), // status bar color
),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Zulu real estate',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
routes: {
Routes.propertyDetails: (context) => PropertyDetail(),
Routes.propertyAgent: (context) => AgentScreen(),
});
}
}
class MyHttpOverrides extends HttpOverrides {
@override
HttpClient createHttpClient(SecurityContext? context) {
return super.createHttpClient(context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
}
}
”’导入’package:mongo_dart/mongo_dart.dart’;
class MongoDbConnection {
static var dbUrl, dbCollection;
static dbConnect() async {
dbUrl = await Db.create(
"mongodb+srv://abdi:abdi@cluster0.soti0.mongodb.net/myFirstDatabase?retryWrites=true&w=majority");
await dbUrl.open(secure: true);
dbCollection = dbUrl.collection("agents");
}
}
”’
© 版权声明
本站下载的源码均来自公开网络收集转发二次开发而来,
若侵犯了您的合法权益,请来信通知我们1413333033@qq.com,
我们会及时删除,给您带来的不便,我们深表歉意。
下载用户仅供学习交流,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担,访问及下载者下载默认同意本站声明的免责申明,请合理使用切勿商用。
THE END
暂无评论内容