fluttercommunity / fluttercommunity/chewie

Creating Dynamic aspect ratio as user changes it

Open
#313 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Dart
Stars
2.1k
Forks
1.1k
Avg merge
6d 8h
Merged PRs (30d)
6

Description

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class ChewieListItem extends StatefulWidget {
// This will contain the URL/asset path which we want to play
final VideoPlayerController videoPlayerController;
final bool looping;
final double ratio;

ChewieListItem({
@required this.videoPlayerController,
this.looping,
this.ratio,
Key key,
}) : super(key: key);

@override
_ChewieListItemState createState() => _ChewieListItemState();
}

class _ChewieListItemState extends State {
ChewieController _chewieController;
double ratio;

@override
void setState(fn) {
ratio = widget.ratio;
super.setState(fn);
}

@override
void initState() {
super.initState();
// Wrapper on top of the videoPlayerController
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: ratio,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: widget.looping,
// Errors can occur for example when trying to play a video
// from a non-existent URL
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
);
}

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
);
}

@override
void dispose() {
super.dispose();
// IMPORTANT to dispose of all the used resources

widget.videoPlayerController.dispose();
_chewieController.dispose();
}
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.