Skip to content

Commit

Permalink
Merge pull request #43 from Joran-Dob/null-safety
Browse files Browse the repository at this point in the history
Updated null safety implementation, stricter lint rules 👷‍♂️
  • Loading branch information
Joran-Dob committed Mar 7, 2021
2 parents 2064724 + 44bb5bd commit 04ba044
Show file tree
Hide file tree
Showing 57 changed files with 1,771 additions and 531 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.0.0] - 7/03/2021.

* Migrated to sound null safety.
* Cleaned up null safety code and typing.
* Fixed some deprecation issues.
* Changed linting rules to be stricter.

## [2.0.0-nullsafety.0] - 3/02/2021.

* Migrated to sound null safety.
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
# subtitle_wrapper_package

[![](https://img.shields.io/badge/pub-v1.0.3-brightgreen.svg)](https://pub.dev/packages/subtitle_wrapper_package)
![Test and publish package](https://github.com/Joran-Dob/flutter_subtitle_wrapper/workflows/Test%20and%20publish%20package/badge.svg?branch=master)
[![](https://img.shields.io/badge/pub-v2.0.0-brightgreen.svg)](https://pub.dev/packages/subtitle_wrapper_package)

[![Test and (dry-run) publish package](https://github.com/Joran-Dob/flutter_subtitle_wrapper/actions/workflows/flutter-drive.yml/badge.svg)](https://github.com/Joran-Dob/flutter_subtitle_wrapper/actions/workflows/flutter-drive.yml)

[![codecov](https://codecov.io/gh/Joran-Dob/flutter_subtitle_wrapper/branch/master/graph/badge.svg)](https://codecov.io/gh/Joran-Dob/flutter_subtitle_wrapper)
[![licence](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/IamTobi/spotify_sdk/blob/master/LICENSE)

## Features

Subtitle playback for the 2 most widely used subtitle formats are supported currently which can be dynamicly updated during playback from a url of content string. As well as basic styling of the subtitle text item.

The package is nearly completely unit tested and widget tests are in progress.

| Function | Description| Implemented |
|---|---|---|
| Parse WebVTT | Parsing of WebVtt subtitles. | :heavy_check_mark: |
| Parse SubRip (.srt) | Parsing of SubRip subtitles. | :heavy_check_mark: |
| Remote loading utf8 encoded subtitles | The parsing of subtitle files with the utf8 encoding from an url.| :heavy_check_mark: |
| Remote loading latin1 encoded subtitles |The parsing of subtitle files with the latin1 encoding from an url. | :heavy_check_mark: |
| Dynamic updating of subtitle | Update subtitle content during playback. | :heavy_check_mark: |
| Standard subtitle styling | Standard styling of subtitle items. | :heavy_check_mark: |
| Advance subtitle styling | Advance styling of subtitle items. Like custom fonts.| :construction_worker: |

| Parse WebVTT | Parsing of WebVtt subtitles. ||
| Parse SubRip (.srt) | Parsing of SubRip subtitles. ||
| Remote loading utf8 encoded subtitles | The parsing of subtitle files with the utf8 encoding from an url.||
| Remote loading latin1 encoded subtitles |The parsing of subtitle files with the latin1 encoding from an url. ||
| Dynamic updating of subtitle | Update subtitle content during playback. ||
| Standard subtitle styling | Standard styling of subtitle items. ||
| Advance subtitle styling | Advance styling of subtitle items. Like custom fonts.| 🚧 |

## Installation

The basic setup of the package is really straight forward, create a instance of `SubtitleController` with a `subtitleUrl` or `subtitlesContent` depending if your resource is remote or local.

Unfortunately currently its required to specify the subtitle type so `webvtt` or `srt`.
Unfortunately currently its required to specify the subtitle type so `webvtt` or `srt` .

After this you need to wrap your video player with the `SubTitleWrapper` and add the `SubtitleController` and `videoPlayerController` to the `SubTitleWrapper`. That's it :tada:
After this you need to wrap your video player with the `SubTitleWrapper` and add the `SubtitleController` and `videoPlayerController` to the `SubTitleWrapper` . That's it :tada:

``` dart
final SubtitleController subtitleController = SubtitleController(
Expand Down
7 changes: 1 addition & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
include: package:pedantic/analysis_options.yaml

linter:
rules:
close_sinks: true
package_api_docs: true
include: package:lint/analysis_options_package.yaml
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"video_player","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-1.0.1/","dependencies":[]},{"name":"wakelock","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.2.1+1/","dependencies":[]}],"android":[{"name":"video_player","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player-1.0.1/","dependencies":[]},{"name":"wakelock","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.2.1+1/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"import_js_library","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/import_js_library-1.0.2/","dependencies":[]},{"name":"video_player_web","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_web-0.1.4+1/","dependencies":[]},{"name":"wakelock_web","path":"/Users/joran.dob/Flutter/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock_web-0.1.0+3/","dependencies":["import_js_library"]}]},"dependencyGraph":[{"name":"import_js_library","dependencies":[]},{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]},{"name":"wakelock","dependencies":["wakelock_web"]},{"name":"wakelock_web","dependencies":["import_js_library"]}],"date_created":"2021-02-03 15:06:02.615412","version":"1.26.0-12.0.pre"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"video_player","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/video_player-2.0.0/","dependencies":[]},{"name":"wakelock","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/wakelock-0.4.0/","dependencies":[]}],"android":[{"name":"video_player","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/video_player-2.0.0/","dependencies":[]},{"name":"wakelock","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/wakelock-0.4.0/","dependencies":[]}],"macos":[{"name":"wakelock_macos","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/wakelock_macos-0.1.0/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"video_player_web","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/video_player_web-2.0.0/","dependencies":[]},{"name":"wakelock_web","path":"/Users/joran.dob/.pub-cache/hosted/pub.dartlang.org/wakelock_web-0.2.0/","dependencies":[]}]},"dependencyGraph":[{"name":"video_player","dependencies":["video_player_web"]},{"name":"video_player_web","dependencies":[]},{"name":"wakelock","dependencies":["wakelock_macos","wakelock_web"]},{"name":"wakelock_macos","dependencies":[]},{"name":"wakelock_web","dependencies":[]}],"date_created":"2021-03-07 15:24:57.038061","version":"2.0.0"}
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lint/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
18 changes: 18 additions & 0 deletions example/android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
8 changes: 4 additions & 4 deletions example/lib/data/sw_constants.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mixin SwConstants {
static final String videoUrl =
static const String videoUrl =
'https://d11b76aq44vj33.cloudfront.net/media/720/video/5def7824adbbc.mp4';

// Subtitles
static final String enSubtitle = 'https://pastebin.com/raw/W5rF45tN';
static final String esSubtitle = 'https://pastebin.com/raw/tsT3qtHf';
static final String nlSubtitle = 'https://pastebin.com/raw/L0qEE0cA';
static const String enSubtitle = 'https://pastebin.com/raw/W5rF45tN';
static const String esSubtitle = 'https://pastebin.com/raw/tsT3qtHf';
static const String nlSubtitle = 'https://pastebin.com/raw/L0qEE0cA';
}
53 changes: 21 additions & 32 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,40 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
home: MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({
const MyHomePage({
Key key,
}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState(
SwConstants.videoUrl,
);
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
VideoPlayerController videoPlayerController;
ChewieController chewieController;
final String link;
final String link = SwConstants.videoUrl;
final SubtitleController subtitleController = SubtitleController(
subtitleUrl: SwConstants.enSubtitle,
showSubtitles: true,
subtitleDecoder: SubtitleDecoder.utf8,
subtitleType: SubtitleType.webvtt,
);

_MyHomePageState(
this.link,
);

VideoPlayerController getVideoPlayerController() {
videoPlayerController ??= VideoPlayerController.network(link);
return videoPlayerController;
VideoPlayerController get videoPlayerController {
return VideoPlayerController.network(link);
}

ChewieController getChewieController() {
chewieController ??= ChewieController(
videoPlayerController: getVideoPlayerController(),
ChewieController get chewieController {
return ChewieController(
videoPlayerController: videoPlayerController,
aspectRatio: 3 / 2,
autoPlay: true,
autoInitialize: true,
allowFullScreen: false,
);
return chewieController;
}

void updateSubtitleUrl({
Expand Down Expand Up @@ -85,34 +73,35 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
var chewieController = getChewieController();
final localChewieController = chewieController;

return Scaffold(
backgroundColor: Color(0xff0b090a),
backgroundColor: const Color(0xff0b090a),
body: Column(
children: [
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).padding.top,
),
child: Container(
child: SizedBox(
height: 270,
child: SubTitleWrapper(
videoPlayerController: chewieController.videoPlayerController,
videoPlayerController:
localChewieController.videoPlayerController,
subtitleController: subtitleController,
subtitleStyle: SubtitleStyle(
subtitleStyle: const SubtitleStyle(
textColor: Colors.white,
hasBorder: true,
),
videoChild: Chewie(
controller: chewieController,
controller: localChewieController,
),
),
),
),
Expanded(
child: Container(
color: Color(
color: const Color(
0xff161a1d,
),
child: Row(
Expand Down Expand Up @@ -157,7 +146,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
),
Divider(
const Divider(
color: Colors.grey,
),
Row(
Expand All @@ -180,7 +169,7 @@ class _MyHomePageState extends State<MyHomePage> {
subtitleLanguage:
ExampleSubtitleLanguage.english,
),
child: Text('Switch to 🇬🇧'),
child: const Text('Switch to 🇬🇧'),
),
ElevatedButton(
style: ButtonStyle(
Expand All @@ -199,7 +188,7 @@ class _MyHomePageState extends State<MyHomePage> {
subtitleLanguage:
ExampleSubtitleLanguage.spanish,
),
child: Text('Switch to 🇪🇸'),
child: const Text('Switch to 🇪🇸'),
),
ElevatedButton(
style: ButtonStyle(
Expand All @@ -218,7 +207,7 @@ class _MyHomePageState extends State<MyHomePage> {
subtitleLanguage:
ExampleSubtitleLanguage.dutch,
),
child: Text('Switch to 🇳🇱'),
child: const Text('Switch to 🇳🇱'),
),
],
),
Expand Down
6 changes: 6 additions & 0 deletions example/macos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/xcuserdata/
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
2 changes: 2 additions & 0 deletions example/macos/Flutter/Flutter-Release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
12 changes: 12 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Generated file. Do not edit.
//

import FlutterMacOS
import Foundation

import wakelock_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
}
40 changes: 40 additions & 0 deletions example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
platform :osx, '10.11'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end
16 changes: 16 additions & 0 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- FlutterMacOS (1.0.0)

DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral`)

EXTERNAL SOURCES:
FlutterMacOS:
:path: Flutter/ephemeral

SPEC CHECKSUMS:
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424

PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c

COCOAPODS: 1.10.1
Loading

0 comments on commit 04ba044

Please sign in to comment.