Flutter
i am using video_trimmer: ^0.5.2 plugin , which allows cutting and editing the video before uploading ,on pressed so everything work fine from the first time but if i reopen the editor again by clicking the bottom, video will be shown without the TrimmerEditor widget with this error Cannot add new events after calling close but if left the page and re-entered again, everything will work fine except if i click again and again with keeping in the same UI page !
i already know that happen because of the widget which is close again from the stack IF (true or false ) but i need a solution with same my code cuse i have big complicated project in the same code
class VideoTrimmer extends StatefulWidget {
const VideoTrimmer({Key key}) : super(key: key);
@override
_VideoTrimmerState createState() => _VideoTrimmerState();
}
class _VideoTrimmerState extends State<VideoTrimmer> {
Trimmer _trimmer = Trimmer(); // this object from the package its self
double _startValue = 0.0;
double _endValue = 0.0;
bool _isPlaying = false;
bool displayWidget = false;
_loadVideo() {
_trimmer.loadVideo(videoFile: file);
}
@override
void dispose() {
super.dispose();
_trimmer.dispose(); // i tried to remove this too , but same issue
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Stack(
children: [
TextButton(
onPressed: (){
final result = await FilePicker.platform.pickFiles(allowMultiple: false );
if (result == null) return;
final path = result.files.single.path;
setState(() => file = File(path));
_loadVideo();
setState(() => displayWidget = true);
},
child: Text("selectVideo")
),
displayWidget ?
Center(
child: Container(
padding: EdgeInsets.only(bottom: 30.0),
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: VideoViewer(trimmer: _trimmer),
),
Center(
child: TrimEditor( // here is the issue happen
trimmer: _trimmer,
viewerHeight: 50.0,
viewerWidth: MediaQuery.of(context).size.width,
maxVideoLength: Duration(seconds: 60),
onChangeStart: (value) {
_startValue = value;
},
onChangeEnd: (value) {
_endValue = value;
},
onChangePlaybackState: (value) {
if(!mounted) {
setState(() =>
_isPlaying = value);
}
},
),
),
TextButton(
child: _isPlaying
? Icon(
Icons.pause,
size: 80.0,
color: Colors.white,
)
: Icon(
Icons.play_arrow,
size: 80.0,
color: Colors.white,
),
onPressed: () async {
bool playbackState = await _trimmer.videPlaybackControl(
startValue: _startValue,
endValue: _endValue,
);
if(!mounted) {
setState(() =>
_isPlaying = playbackState);
}
},
),
ElevatedButton(
child: Text("SAVE"),
onPressed: () {
uploadVideo();
setState(() => displayWidget = false);
},
),
],
),
),
),
],
),
);
}
}