netease_callkit 3.6.2 copy "netease_callkit: ^3.6.2" to clipboard
netease_callkit: ^3.6.2 copied to clipboard

netease callkit is a kit about audio&video calls launched by CommsEase.

example/lib/main.dart

// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

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

import 'package:flutter/services.dart';
import 'package:netease_callkit/netease_callkit.dart';
import 'config/app_config.dart';
import 'base/device_manager.dart';
import 'service/auth/auth_manager.dart';
import 'utils/nav_register.dart';
import 'constants/router_name.dart';

void main() {
  runZonedGuarded<Future<void>>(() async {
    WidgetsFlutterBinding.ensureInitialized();

    // 初始化应用配置
    await AppConfig().init();

    // 初始化设备管理器
    await DeviceManager().init();

    // 初始化认证管理器
    await AuthManager().init();

    // 初始化 CallKit
    await initCallKit();

    runApp(const MyApp());
  }, (Object error, StackTrace stack) {
    print('crash exception: $error \ncrash stack: $stack');
  });
}

/// 初始化 CallKit
Future<void> initCallKit() async {
  try {
    final callkit = NECallEngine.instance;

    // 调用 CallKit 初始化接口
    final result = await callkit.setup(NESetupConfig(
      appKey: AppConfig().appKey,
      enableJoinRtcWhenCall: true,
      initRtcMode: NECallInitRtcMode.global,
    ));

    if (result.code == 0) {
      print('CallKit 初始化成功');
    } else {
      print('CallKit 初始化失败: ${result.msg}');
    }
  } catch (e) {
    print('CallKit 初始化异常: $e');
  }
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      color: Colors.black,
      theme: ThemeData(
        brightness: Brightness.light,
        appBarTheme: const AppBarTheme(
          systemOverlayStyle: SystemUiOverlayStyle.light,
        ),
      ),
      themeMode: ThemeMode.light,
      home: const WelcomePage(),
      onGenerateRoute: (settings) {
        WidgetBuilder builder =
            RoutesRegister.routes(settings)[settings.name] as WidgetBuilder;
        return MaterialPageRoute(
          builder: (ctx) => builder(ctx),
          settings: RouteSettings(name: settings.name),
        );
      },
    );
  }
}

class WelcomePage extends StatefulWidget {
  const WelcomePage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _WelcomePageState();
}

class _WelcomePageState extends State<WelcomePage> {
  @override
  void initState() {
    super.initState();
    loadLoginInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            CircularProgressIndicator(
              valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
            ),
            SizedBox(height: 16),
            Text(
              '正在加载...',
              style: TextStyle(
                color: Colors.white,
                fontSize: 16,
              ),
            ),
          ],
        ),
      ),
    );
  }

  void loadLoginInfo() {
    AuthManager().autoLogin().then((value) {
      if (value) {
        Navigator.of(context).pushNamedAndRemoveUntil(
          RouterName.homePage,
          (route) => false,
        );
      } else {
        Navigator.of(context).pushNamedAndRemoveUntil(
          RouterName.loginPage,
          (route) => false,
        );
      }
    });
  }
}
2
likes
145
points
174
downloads

Publisher

verified publisheryunxin.163.com

Weekly Downloads

netease callkit is a kit about audio&video calls launched by CommsEase.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, hawk_meta, netease_common, path_provider, yunxin_alog

More

Packages that depend on netease_callkit

Packages that implement netease_callkit