cicare_rtc_flutter 1.0.0 copy "cicare_rtc_flutter: ^1.0.0" to clipboard
cicare_rtc_flutter: ^1.0.0 copied to clipboard

A professional RTC SDK for Flutter providing App-to-App and SIP calling with WhatsApp-style UI and FCM integration.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:cicare_rtc_flutter/cicare_rtc_flutter.dart';
import 'screens/login_page.dart';
import 'screens/dashboard_page.dart';
import 'services/auth_service.dart';
import 'models/user.dart';
import 'models/call_state.dart';

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

// Global status for call tracking
final ValueNotifier<CallState> callStateNotifier = ValueNotifier(CallState());

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(const ExampleApp());
}

class ExampleApp extends StatefulWidget {
  const ExampleApp({super.key});
  @override
  State<ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<ExampleApp> {
  final _sdk = CicareRtcFlutter();

  @override
  void initState() {
    super.initState();
    _sdk.setAPI(
      baseUrl: "https://your-endpoint/",
      token: "your-token-here",
    );
    _setupMessaging();
    _setupRtcCallbacks();
  }

  void _setupRtcCallbacks() {
    CicareRtcFlutter.setOnCallStateChanged((state) {
      debugPrint('RTC: Call state changed: $state');
      // Update global state while preserving current callee info if applicable
      callStateNotifier.value = callStateNotifier.value.copyWith(
        status: _mapStringToStatus(state),
      );
    });

    CicareRtcFlutter.setOnCallError((code, message) {
      debugPrint('RTC: Call Error: [$code] $message');
      callStateNotifier.value = callStateNotifier.value.copyWith(
        status: CallStatus.error,
        errorMessage: message,
      );
    });
  }

  CallStatus _mapStringToStatus(String state) {
    switch (state.toUpperCase()) {
      case 'CALLING': return CallStatus.calling;
      case 'RINGING': return CallStatus.ringing;
      case 'CONNECTED': return CallStatus.connected;
      case 'DISCONNECTED': return CallStatus.ended;
      default: return CallStatus.idle;
    }
  }

  Future<void> _setupMessaging() async {
    try {
      await FirebaseMessaging.instance.requestPermission();
      
      FirebaseMessaging.instance.onTokenRefresh.listen((token) {
        AuthService.syncFcmToken();
      });

      FirebaseMessaging.onMessage.listen((msg) {
        debugPrint('FCM: Foreground message: ${msg.data}');
      });
    } catch (e) {
      debugPrint('FCM: Setup error: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,
      title: 'CiCare SDK Call',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      routes: {
        '/': (c) => const _Startup(),
        '/login': (c) => const LoginPage(),
        '/dashboard': (c) => const DashboardPage(),
      },
    );
  }
}

class _Startup extends StatefulWidget {
  const _Startup({super.key});
  @override
  State<_Startup> createState() => _StartupState();
}

class _StartupState extends State<_Startup> {
  @override
  void initState() {
    super.initState();
    _checkLogin();
  }

  Future<void> _checkLogin() async {
    final user = await AuthService.getUser();
    if (!mounted) return;
    
    if (user != null) {
      Navigator.of(context).pushReplacementNamed('/dashboard');
    } else {
      Navigator.of(context).pushReplacementNamed('/login');
    }
  }

  @override
  Widget build(BuildContext context) {
    return const Scaffold(body: Center(child: CircularProgressIndicator()));
  }
}
1
likes
135
points
38
downloads

Publisher

unverified uploader

Weekly Downloads

A professional RTC SDK for Flutter providing App-to-App and SIP calling with WhatsApp-style UI and FCM integration.

Homepage
Repository
View/report issues

Topics

#rtc #voip #sip #call #fcm

Documentation

API reference

License

MIT (license)

Dependencies

cupertino_icons, firebase_core, firebase_messaging, flutter, plugin_platform_interface

More

Packages that depend on cicare_rtc_flutter

Packages that implement cicare_rtc_flutter