我正在尝试连接我的flutter聊天应用程序与Docker服务器(Rethinkdb),但顶部的错误显示
下面是我的CompositionRoot.dart:
import 'package:chat/chat.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_newapp/src/blocs/onBoarding/onboarding_cubit.dart';
import 'package:flutter_newapp/src/blocs/onBoarding/prfil_image_cubit.dart';
import 'package:flutter_newapp/src/data/Services/image_uploader.dart';
import 'package:flutter_newapp/src/data/Services/local_cache.dart';
import 'package:flutter_newapp/src/presentation/screen/onBoarding/onboarding.dart';
import 'package:rethink_db_ns/rethink_db_ns.dart';
import 'package:shared_preferences/shared_preferences.dart';
class CompositionRoot {
static late SharedPreferences _sharedPreferences;
static late RethinkDb _r;
static late Connection _connection;
static late IUserService _userService;
static late ILocalCache _localCache;
static late ImageUploader imageUploader;
static configure() async {
_r = RethinkDb();
_connection = await _r.connect(host: "127.0.0.1", port: 28015);
_userService = UserService(_r, _connection);
_localCache = LocalCache(_sharedPreferences);
}
static Widget composeOnboardingUi() {
ImageUploader imageUploader = ImageUploader('http://localhost:3000/upload');
OnBoardingCubit onboardingCubit =
OnBoardingCubit(_userService, _localCache, imageUploader);
return MultiBlocProvider(providers:[
BlocProvider(create: (BuildContext context) => onboardingCubit ),
BlocProvider(create: (BuildContext context) => ProfileImageCubit() )
], child: OnBoardingScreen());
}
}
这里有许多主要的.dart文件:
import 'package:flutter/material.dart';
import 'package:flutter_newapp/core/app_theme.dart';
import 'package:flutter_newapp/src/presentation/screen/onBoarding/onboarding.dart';
import 'composition_root.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await CompositionRoot.configure();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Chat App',
debugShowCheckedModeBanner: false,
theme: lightTheme(context),
darkTheme: darkTheme(context),
home: CompositionRoot.composeOnboardingUi(),
);
}
}
rethinkdb已经在运行,如您所见:
我尝试127.0.0.1通过计算机的IP地址更改www.example.com,但仍然显示相同的问题
1条答案
按热度按时间puruo6ea1#
“localhost”和“127.0.0.1“应该替换为“10.0.2.2“,它为我解决了这个问题