video_trim_editor 0.1.0 copy "video_trim_editor: ^0.1.0" to clipboard
video_trim_editor: ^0.1.0 copied to clipboard

A beautiful and customizable video trimmer widget for Flutter with timeline preview, drag-to-trim handles, and playback controls.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:video_trim_editor/video_trim_editor.dart';
import 'package:image_picker/image_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video Trimmer Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  File? _trimmedVideo;
  final ImagePicker _picker = ImagePicker();

  Future<void> _pickAndTrimVideo() async {
    try {
      // Pick a video from gallery
      final XFile? video = await _picker.pickVideo(source: ImageSource.gallery);

      if (video == null) return;

      if (!mounted) return;

      // Navigate to trimmer screen
      final trimmedVideo = await Navigator.push<File>(
        context,
        MaterialPageRoute(
          builder:
              (context) => VideoTrimmerWidget(
                videoFile: File(video.path),
                maxDuration: const Duration(seconds: 30),
                theme: VideoTrimmerTheme.dark().copyWith(
                  accentColor: Colors.deepPurple,
                ),
                onError: (error, stackTrace) {
                  debugPrint('Trimmer Error: $error');
                },
                onInfo: (message) {
                  debugPrint('Trimmer Info: $message');
                },
              ),
        ),
      );

      if (trimmedVideo != null) {
        setState(() {
          _trimmedVideo = trimmedVideo;
        });
      }
    } catch (e) {
      debugPrint('Error: $e');
      if (mounted) {
        ScaffoldMessenger.of(
          context,
        ).showSnackBar(SnackBar(content: Text('Error: $e')));
      }
    }
  }

  Future<void> _pickAndTrimVideoWithCustomTheme() async {
    try {
      final XFile? video = await _picker.pickVideo(source: ImageSource.gallery);

      if (video == null) return;

      if (!mounted) return;

      // Navigate to trimmer with light theme
      final trimmedVideo = await Navigator.push<File>(
        context,
        MaterialPageRoute(
          builder:
              (context) => VideoTrimmerWidget(
                videoFile: File(video.path),
                maxDuration: const Duration(minutes: 1),
                theme: VideoTrimmerTheme.light().copyWith(
                  accentColor: Colors.blue,
                ),
                appBarTitle: 'Edit Video',
                continueButtonText: 'DONE',
              ),
        ),
      );

      if (trimmedVideo != null) {
        setState(() {
          _trimmedVideo = trimmedVideo;
        });
      }
    } catch (e) {
      debugPrint('Error: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Video Trimmer Example'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Icon(
                Icons.video_library,
                size: 100,
                color: Colors.deepPurple,
              ),
              const SizedBox(height: 32),
              const Text(
                'Video Trim Editor',
                style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 16),
              const Text(
                'A beautiful video trimming widget for Flutter',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16, color: Colors.grey),
              ),
              const SizedBox(height: 48),
              ElevatedButton.icon(
                onPressed: _pickAndTrimVideo,
                icon: const Icon(Icons.video_call),
                label: const Text('Pick & Trim Video (Dark Theme)'),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 24,
                    vertical: 16,
                  ),
                  textStyle: const TextStyle(fontSize: 16),
                ),
              ),
              const SizedBox(height: 16),
              OutlinedButton.icon(
                onPressed: _pickAndTrimVideoWithCustomTheme,
                icon: const Icon(Icons.light_mode),
                label: const Text('Pick & Trim Video (Light Theme)'),
                style: OutlinedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 24,
                    vertical: 16,
                  ),
                  textStyle: const TextStyle(fontSize: 16),
                ),
              ),
              if (_trimmedVideo != null) ...[
                const SizedBox(height: 32),
                const Divider(),
                const SizedBox(height: 16),
                const Text(
                  'Last Trimmed Video:',
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 8),
                Container(
                  padding: const EdgeInsets.all(12),
                  decoration: BoxDecoration(
                    color: Colors.grey.shade200,
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      const Icon(Icons.check_circle, color: Colors.green),
                      const SizedBox(width: 8),
                      Flexible(
                        child: Text(
                          _trimmedVideo!.path.split('/').last,
                          overflow: TextOverflow.ellipsis,
                          style: const TextStyle(fontSize: 14),
                        ),
                      ),
                    ],
                  ),
                ),
                const SizedBox(height: 8),
                Text(
                  'Size: ${(_trimmedVideo!.lengthSync() / 1024 / 1024).toStringAsFixed(2)} MB',
                  style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

A beautiful and customizable video trimmer widget for Flutter with timeline preview, drag-to-trim handles, and playback controls.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

file_picker, flutter, flutter_native_video_trimmer, flutter_riverpod, freezed_annotation, path_provider, riverpod_annotation, video_player, video_thumbnail

More

Packages that depend on video_trim_editor