Flutterにおいてビデオを扱う方法について

概要

このノートはカメラからビデオ取得ギャラリーからビデオ取得関数を使用する。
よって前読み推奨。

以下にコード例を示す。

@override
Widget build(BuildContext context) {
	return Scaffold(
		appBar: AppBar(
			title: Text(widget.title),
		),
		body: Center(
			child: _controller == null
				? Text(
					"ビデオを選択してください",
					style: Theme.of(context).textTheme.headline4,
				)
				: VideoPlayer(_controller!))
		),
		floatingActionButton:
			Row(
				mainAxisAlignment: MainAxisAlignment.spaceEvenly,
				children: [
					FloatingActionButton(
						onPressed: getVideoFromCamera,
						child: const Icon(Icons.video_call),
					),
					FloatingActionButton(
						onPressed: getVideoFromGarally,
						child: const Icon(Icons.movie_creattion),
					),
				],
			),
	);
}

FloatingActionButtonによってカメラとギャラリーから写真を取得する。

child: _controller == null
	? Text(
		"ビデオを選択してください",
		style: Theme.of(context).textTheme.headline4,
	)
	: VideoPlayer(_controller!))

このコードによって、_controllernullでない場合に、ビデオをbodyVideoPlayerで挿入している。