polyv_live_scenes 0.0.3 copy "polyv_live_scenes: ^0.0.3" to clipboard
polyv_live_scenes: ^0.0.3 copied to clipboard

Polyv Live Scenes Flutter plugin for opening native live watching rooms on Android and iOS.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(title: '保利威直播', home: LoginPage());
  }
}

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

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final _plugin = PolyvLiveScenes();

  final _appIdController = TextEditingController();
  final _userIdController = TextEditingController();
  final _appSecretController = TextEditingController();
  final _channelIdController = TextEditingController();

  bool _loading = false;
  String _statusMsg = '';

  Future<void> _login() async {
    if (_appIdController.text.trim().isEmpty ||
        _userIdController.text.trim().isEmpty ||
        _appSecretController.text.trim().isEmpty ||
        _channelIdController.text.trim().isEmpty) {
      setState(() => _statusMsg = '请填写完整的账号和频道参数');
      return;
    }

    setState(() {
      _loading = true;
      _statusMsg = '登录中...';
    });

    try {
      await _plugin.loginLiveRoom(
        channelType: 0,
        channelId: _channelIdController.text.trim(),
        userId: _userIdController.text.trim(),
        appId: _appIdController.text.trim(),
        appSecret: _appSecretController.text.trim(),
      );
      setState(() => _statusMsg = '登录成功,直播间已打开');
    } on PlatformException catch (e) {
      final details = e.details == null ? '' : '\n${e.details}';
      setState(() => _statusMsg = '登录失败:${e.message}$details');
    } catch (e) {
      setState(() => _statusMsg = '未知错误:$e');
    } finally {
      setState(() => _loading = false);
    }
  }

  @override
  void dispose() {
    _appIdController.dispose();
    _userIdController.dispose();
    _appSecretController.dispose();
    _channelIdController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('多场景直播登录')),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const SizedBox(height: 16),
            _buildField('App ID', _appIdController),
            const SizedBox(height: 12),
            _buildField('User ID', _userIdController),
            const SizedBox(height: 12),
            _buildField('App Secret', _appSecretController, obscure: true),
            const SizedBox(height: 12),
            _buildField('Channel ID', _channelIdController),
            const SizedBox(height: 32),
            SizedBox(
              height: 50,
              child: ElevatedButton(
                onPressed: _loading ? null : _login,
                child: _loading
                    ? const SizedBox(
                        width: 22,
                        height: 22,
                        child: CircularProgressIndicator(
                          strokeWidth: 2,
                          color: Colors.white,
                        ),
                      )
                    : const Text('进入直播间', style: TextStyle(fontSize: 16)),
              ),
            ),
            if (_statusMsg.isNotEmpty) ...[
              const SizedBox(height: 20),
              Text(
                _statusMsg,
                textAlign: TextAlign.center,
                style: TextStyle(
                  color:
                      _statusMsg.contains('失败') ||
                          _statusMsg.contains('错误') ||
                          _statusMsg.contains('填写')
                      ? Colors.red
                      : Colors.green,
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }

  Widget _buildField(
    String label,
    TextEditingController controller, {
    bool obscure = false,
  }) {
    return TextField(
      controller: controller,
      obscureText: obscure,
      decoration: InputDecoration(
        labelText: label,
        border: const OutlineInputBorder(),
        contentPadding: const EdgeInsets.symmetric(
          horizontal: 12,
          vertical: 14,
        ),
      ),
    );
  }
}
0
likes
150
points
95
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Polyv Live Scenes Flutter plugin for opening native live watching rooms on Android and iOS.

Homepage

Topics

#polyv #live-streaming #video #flutter-plugin

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on polyv_live_scenes

Packages that implement polyv_live_scenes