Skip to content

Commit

Permalink
Merge pull request fluttercommunity#828 from EmreDET/fix-is-finished-bug
Browse files Browse the repository at this point in the history
Fix the logic of the Center Play Button icon selection
  • Loading branch information
diegotori authored Aug 5, 2024
2 parents 1fa89df + ac05d15 commit 039c793
Show file tree
Hide file tree
Showing 27 changed files with 416 additions and 71 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Check format
Expand All @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Install Package Dependencies
Expand All @@ -41,15 +41,16 @@ jobs:
- name: Lint using flutter analyze
run: flutter analyze .

# test:
# name: Test2
# runs-on: ubuntu-latest
test:
name: Run tests.
runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - uses: subosito/flutter-action@v1
# with:
# channel: beta
# - name: Test
# run: flutter test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Run flutter test
run: |
flutter pub get
flutter test
26 changes: 24 additions & 2 deletions example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,27 @@
# This file should be version controlled and should not be manually edited.

version:
revision: ab4506cad2a860e1cb6186c0957eeb86024a7c6b
channel: dev
revision: "b0850beeb25f6d5b10426284f506557f66181b36"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36
- platform: ios
create_revision: b0850beeb25f6d5b10426284f506557f66181b36
base_revision: b0850beeb25f6d5b10426284f506557f66181b36

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
1 change: 1 addition & 0 deletions example/ios/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/dgph
*.mode1v3
*.mode2v3
*.moved-aside
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
264 changes: 222 additions & 42 deletions example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,19 @@
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "331C8080294A63A400263BE5"
BuildableName = "RunnerTests.xctest"
BlueprintName = "RunnerTests"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -61,8 +70,6 @@
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Profile"
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UIKit
import Flutter
import UIKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Example</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand Down
12 changes: 12 additions & 0 deletions example/ios/RunnerTests/RunnerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Flutter
import UIKit
import XCTest

class RunnerTests: XCTestCase {

func testExample() {
// If you add code to the Runner application, consider adding tests here.
// See https://developer.apple.com/documentation/xctest for more information about using XCTest.
}

}
6 changes: 4 additions & 2 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
}

Widget _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool isFinished = (_latestValue.position >= _latestValue.duration) &&
_latestValue.duration.inSeconds > 0;
final bool showPlayButton =
widget.showPlayButton && !_latestValue.isPlaying && !_dragging;

Expand Down Expand Up @@ -726,7 +727,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
}

void _playPause() {
final isFinished = _latestValue.position >= _latestValue.duration;
final isFinished = _latestValue.position >= _latestValue.duration &&
_latestValue.duration.inSeconds > 0;

setState(() {
if (controller.value.isPlaying) {
Expand Down
6 changes: 4 additions & 2 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ class _MaterialControlsState extends State<MaterialControls>
}

Widget _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool isFinished = (_latestValue.position >= _latestValue.duration) &&
_latestValue.duration.inSeconds > 0;
final bool showPlayButton =
widget.showPlayButton && !_dragging && !notifier.hideStuff;

Expand Down Expand Up @@ -519,7 +520,8 @@ class _MaterialControlsState extends State<MaterialControls>
}

void _playPause() {
final isFinished = _latestValue.position >= _latestValue.duration;
final bool isFinished = (_latestValue.position >= _latestValue.duration) &&
_latestValue.duration.inSeconds > 0;

setState(() {
if (controller.value.isPlaying) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
}

Widget _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool isFinished = _latestValue.position >= _latestValue.duration &&
_latestValue.duration.inSeconds > 0;
final bool showPlayButton =
widget.showPlayButton && !_dragging && !notifier.hideStuff;

Expand Down
115 changes: 115 additions & 0 deletions test/uninitialized_controls_state_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import 'package:chewie/chewie.dart';
import 'package:chewie/src/center_play_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:video_player/video_player.dart';

List<String> srcs = [
"https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
];

main() {
testWidgets("MaterialControls state test", (WidgetTester tester) async {
// Build our app and trigger a frame.
var videoPlayerController = VideoPlayerController.networkUrl(
Uri.parse(srcs[0]),
);
var materialControlsKey = GlobalKey();
var chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: false,
looping: false,
customControls: MaterialControls(
key: materialControlsKey,
),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Chewie(
controller: chewieController,
),
),
),
);

await tester.pump();

var playButton = find.byType(CenterPlayButton);
expect(playButton, findsOneWidget);
var btn = playButton.first;
var playButtonWidget = tester.widget<CenterPlayButton>(btn);
expect(playButtonWidget.isFinished, false);
});

testWidgets("CupertinoControls state test", (WidgetTester tester) async {
// Build our app and trigger a frame.
var videoPlayerController = VideoPlayerController.networkUrl(
Uri.parse(srcs[0]),
);
var materialControlsKey = GlobalKey();
var chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: false,
looping: false,
customControls: CupertinoControls(
key: materialControlsKey,
backgroundColor: Colors.black,
iconColor: Colors.white,
),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Chewie(
controller: chewieController,
),
),
),
);

await tester.pump();

var playButton = find.byType(CenterPlayButton);
expect(playButton, findsOneWidget);
var btn = playButton.first;
var playButtonWidget = tester.widget<CenterPlayButton>(btn);
expect(playButtonWidget.isFinished, false);
});

testWidgets("MaterialDesktopControls state test",
(WidgetTester tester) async {
// Build our app and trigger a frame.
var videoPlayerController = VideoPlayerController.networkUrl(
Uri.parse(srcs[0]),
);
var materialControlsKey = GlobalKey();
var chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: false,
looping: false,
customControls: MaterialDesktopControls(
key: materialControlsKey,
),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Chewie(
controller: chewieController,
),
),
),
);

await tester.pump();

var playButton = find.byType(CenterPlayButton);
expect(playButton, findsOneWidget);
var btn = playButton.first;
var playButtonWidget = tester.widget<CenterPlayButton>(btn);
expect(playButtonWidget.isFinished, false);
});
}

0 comments on commit 039c793

Please sign in to comment.