import 'package:decorated_flutter/decorated_flutter.dart';
import 'package:demo_widgets/demo_widgets.dart';
import 'package:flutter/material.dart';
import 'package:tencent_live_fluttify/tencent_live_fluttify.dart';

class PusherScreen extends StatefulWidget {
  @override
  _PusherScreenState createState() => _PusherScreenState();
}

class _PusherScreenState extends State<PusherScreen> {
  LivePusher _pusher;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('推流')),
      floatingActionButton: FloatingActionButton(
        onPressed: () {},
        child: Text('重置'),
      ),
      body: DecoratedColumn(
        children: <Widget>[
          Flexible(
            child: CloudVideo(
              onCloudVideoCreated: (controller) async {
                _pusher = await LivePusher.create();
                await _pusher.startPreview(controller);
              },
            ),
          ),
          Flexible(
            child: DecoratedColumn(
              divider: kDividerTiny,
              children: <Widget>[
                DiscreteSetting(
                  head: '设定画面清晰度',
                  options: ['标清', '高清', '超清', '连麦(主)', '连麦(副)'],
                  onSelected: (value) {
                    switch (value) {
                      case '标清':
                        _pusher.setVideoQuality(Quality.STANDARD);
                        break;
                      case '高清':
                        _pusher.setVideoQuality(Quality.HIGH);
                        break;
                      case '超清':
                        _pusher.setVideoQuality(Quality.SUPER_HIGH);
                        break;
                      case '连麦(主)':
                        _pusher.setVideoQuality(Quality.LINKMIC_MAIN);
                        break;
                      case '连麦(副)':
                        _pusher.setVideoQuality(Quality.LINKMIC_SUB);
                        break;
                    }
                  },
                ),
                DiscreteSetting(
                  head: '美颜美白和红润特效',
                  options: ['光滑', '自然', '朦胧'],
                  onSelected: (value) {
                    switch (value) {
                      case '光滑':
                        _pusher.setBeautyFilter(BeautyFilter.SMOOTH);
                        break;
                      case '自然':
                        _pusher.setBeautyFilter(BeautyFilter.NATURE);
                        break;
                      case '朦胧':
                        _pusher.setBeautyFilter(BeautyFilter.HAZY);
                        break;
                    }
                  },
                ),
                DiscreteSetting(
                  head: '色彩滤镜效果',
                  options: [
                    '白兰',
                    '标准',
                    '超脱',
                    '纯真',
                    '粉嫩',
                    '怀旧',
                    '蓝调',
                    '浪漫',
                    '清凉',
                    '清新',
                    '日系',
                    '唯美',
                    '美白',
                    '香粉',
                    '樱红',
                    '元气',
                    '云裳',
                  ],
                  onSelected: (value) {
                    final config = createLocalImageConfiguration(context);
                    switch (value) {
                      case '白兰':
                        _pusher.setFilter(ColorFilter.BAILAN, config);
                        break;
                      case '标准':
                        _pusher.setFilter(ColorFilter.BIAOZHUN, config);
                        break;
                      case '超脱':
                        _pusher.setFilter(ColorFilter.CHAOTUO, config);
                        break;
                      case '纯真':
                        _pusher.setFilter(ColorFilter.CHUNZHEN, config);
                        break;
                      case '粉嫩':
                        _pusher.setFilter(ColorFilter.FENNEN, config);
                        break;
                      case '怀旧':
                        _pusher.setFilter(ColorFilter.HUAIJIU, config);
                        break;
                      case '蓝调':
                        _pusher.setFilter(ColorFilter.LANDIAO, config);
                        break;
                      case '浪漫':
                        _pusher.setFilter(ColorFilter.LANGMAN, config);
                        break;
                      case '清凉':
                        _pusher.setFilter(ColorFilter.QINGLIANG, config);
                        break;
                      case '清新':
                        _pusher.setFilter(ColorFilter.QINGXIN, config);
                        break;
                      case '日系':
                        _pusher.setFilter(ColorFilter.RIXI, config);
                        break;
                      case '唯美':
                        _pusher.setFilter(ColorFilter.WEIMEI, config);
                        break;
                      case '美白':
                        _pusher.setFilter(ColorFilter.WHITE, config);
                        break;
                      case '香粉':
                        _pusher.setFilter(ColorFilter.XIANGFEN, config);
                        break;
                      case '樱红':
                        _pusher.setFilter(ColorFilter.YINGHONG, config);
                        break;
                      case '元气':
                        _pusher.setFilter(ColorFilter.YUANQI, config);
                        break;
                      case '云裳':
                        _pusher.setFilter(ColorFilter.YUNSHANG, config);
                        break;
                    }
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
