builder method

  1. @override
Widget builder(
  1. BuildContext context, [
  2. BoxFit? fit,
  3. double? ratio,
  4. Color? color,
])
override

Implementation

@override
Widget builder(BuildContext context,
    [BoxFit? fit, double? ratio, Color? color]) {
  return ChangeNotifierBuilder(
      notifier: _eventStream,
      builder: (context) {
        return LayoutBuilder(
            builder: (BuildContext context, BoxConstraints box) {
          return Stack(
            alignment: Alignment.center,
            children: [
              Video(
                fit: fit ?? BoxFit.contain,
                controller: _controller,
                width: box.maxWidth,
                height: box.maxWidth / (ratio ?? aspectRatio),
                fill: color ?? Colors.black,
              ),
              if (isBuffering && !hasError)
                Container(
                  height: box.maxWidth / (ratio ?? aspectRatio),
                  width: box.maxWidth,
                  color: Colors.black54,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: const [
                      CircularProgressIndicator(strokeWidth: 1),
                      SizedBox(height: 20),
                      Text(
                        '缓冲中...',
                        style: TextStyle(
                            color: Color.fromARGB(255, 10, 137, 234)),
                      ),
                    ],
                  ),
                ),
              if (_isLoading && !hasError)
                Container(
                  height: box.maxWidth / (ratio ?? aspectRatio),
                  width: box.maxWidth,
                  color: Colors.black54,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: const [
                      CircularProgressIndicator(strokeWidth: 1),
                      SizedBox(height: 20),
                      Text(
                        '加载中...',
                        style: TextStyle(
                            color: Color.fromARGB(255, 10, 137, 234)),
                      ),
                    ],
                  ),
                ),
              if (hasError)
                SizedBox(
                  height: box.maxWidth / (ratio ?? aspectRatio),
                  width: box.maxWidth,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      const Text(
                        '播放错误',
                        style: TextStyle(
                            color: Color.fromARGB(255, 67, 173, 255)),
                      ),
                      const SizedBox(height: 20),
                      Text(
                        errorMessage,
                        style: const TextStyle(
                            color: Color.fromARGB(255, 67, 173, 255)),
                      ),
                    ],
                  ),
                ),
              if (completed)
                SizedBox(
                  height: box.maxWidth / (ratio ?? aspectRatio),
                  width: box.maxWidth,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      IconButton(
                        icon: const Icon(
                          Icons.replay,
                          color: Color.fromARGB(255, 67, 173, 255),
                        ),
                        onPressed: () {
                          _player.playOrPause();
                        },
                      ),
                      TextButton(
                        onPressed: () {
                          _player.playOrPause();
                        },
                        child: const Text(
                          '重新播放',
                          style: TextStyle(
                              color: Color.fromARGB(255, 67, 173, 255)),
                        ),
                      ),
                    ],
                  ),
                ),
            ],
          );
        });
      });
}