em_chat_uikit 2.0.0 copy "em_chat_uikit: ^2.0.0" to clipboard
em_chat_uikit: ^2.0.0 copied to clipboard

A set of ui components adapted to the chat sdk can quickly build a chat page and chat through the chat sdk by invoking the ui components.

example/lib/main.dart

import 'package:em_chat_uikit/chat_uikit.dart';
import 'package:em_chat_uikit_example/debug_login_page.dart';
import 'package:em_chat_uikit_example/demo_localizations.dart';
import 'package:em_chat_uikit_example/home_page.dart';
import 'package:em_chat_uikit_example/login_page.dart';
import 'package:em_chat_uikit_example/notifications/app_settings_notification.dart';
import 'package:em_chat_uikit_example/pages/me/about_page.dart';
import 'package:em_chat_uikit_example/pages/me/personal/personal_info_page.dart';
import 'package:em_chat_uikit_example/pages/me/settings/general_page.dart';
import 'package:em_chat_uikit_example/pages/me/settings/language_page.dart';
import 'package:em_chat_uikit_example/pages/me/settings/translate_page.dart';
// import 'package:em_chat_uikit_example/custom/chat_route_filter.dart';
import 'package:em_chat_uikit_example/tool/settings_data_store.dart';
import 'package:em_chat_uikit_example/welcome_page.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:flutter_easyloading/flutter_easyloading.dart';

import 'pages/me/settings/advanced_page.dart';

const appKey = 'easemob#easeim';

const bool appDebug = false;

void main() async {
  await ChatUIKit.instance.init(
    options: Options(
      appKey: appKey,
      deleteMessagesAsExitGroup: false,
    ),
  );
  SettingsDataStore().init();
  return SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((value) => runApp(const MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final ChatUIKitLocalizations _localization = ChatUIKitLocalizations();

  @override
  void initState() {
    super.initState();
    _localization.defaultLocale = [
      ChatLocal(
          'zh', Map.from(ChatUIKitLocal.zh)..addAll(DemoLocalizations.zh)),
      ChatLocal('en', Map.from(ChatUIKitLocal.en)..addAll(DemoLocalizations.en))
    ];
    // 添加语言后需要进行resetLocales操作
    _localization.resetLocales();
  }

  @override
  Widget build(BuildContext context) {
    return NotificationListener(
      onNotification: (notification) {
        if (notification is AppSettingsNotification) {
          setState(() {});
        }
        return false;
      },
      child: MaterialApp(
        supportedLocales: _localization.supportedLocales,
        localizationsDelegates: _localization.localizationsDelegates,
        localeResolutionCallback: _localization.localeResolutionCallback,
        locale: _localization.currentLocale,
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
          splashColor: Colors.transparent,
          highlightColor: Colors.transparent,
        ),
        builder: EasyLoading.init(
          builder: (context, child) {
            return ChatUIKitTheme(
              color: AppSettingsNotification.isLight
                  ? ChatUIKitColor.light()
                  : ChatUIKitColor.dark(),
              child: child!,
            );
          },
        ),
        home: const WelcomePage(),
        onGenerateRoute: (settings) {
          // RouteSettings newSettings = ChatRouteFilter.chatRouteSettings(settings);
          // return ChatUIKitRoute().generateRoute(newSettings) ??
          return MaterialPageRoute(
            builder: (context) {
              if (settings.name == '/home') {
                return const HomePage();
              } else if (settings.name == '/login') {
                return const LoginPage();
              } else if (settings.name == '/debug_login') {
                return const DebugLoginPage();
              } else if (settings.name == '/personal_info') {
                return const PersonalInfoPage();
              } else if (settings.name == '/general_page') {
                return const GeneralPage();
              } else if (settings.name == '/language_page') {
                return const LanguagePage();
              } else if (settings.name == '/translate_page') {
                return const TranslatePage();
              } else if (settings.name == '/advanced_page') {
                return const AdvancedPage();
              } else if (settings.name == '/about_page') {
                return const AboutPage();
              } else {
                return const SizedBox();
              }
            },
          );
        },
      ),
    );
  }
}
1
likes
0
points
53
downloads

Publisher

unverified uploader

Weekly Downloads

A set of ui components adapted to the chat sdk can quickly build a chat page and chat through the chat sdk by invoking the ui components.

Homepage

License

unknown (license)

Dependencies

audioplayers, cached_network_image, chat_uikit_theme, file_picker, flutter, flutter_localization, flutter_sound_record, im_flutter_sdk, image_picker, path_provider, scroll_to_index, shared_preferences, video_player, video_thumbnail

More

Packages that depend on em_chat_uikit