Skip to content

Commit bfdfc58

Browse files
committed
v3.5.3
add YoutubePlayerExample
1 parent 08924ee commit bfdfc58

8 files changed

+172
-13
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v3.5.3
4+
[2023-01-17]
5+
- Add new heatmap calendar example
6+
- Add like button example
7+
- Add youtube player example
8+
39
## v3.5.2
410
[2022-12-11]
511
- add StoreSecretsExample example on how to store secrets

Diff for: CONTRIBUTING.md

+37-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
1-
https://github.com
1+
# CONTRIBUTING
2+
3+
## contribute by adding a new example page
4+
5+
1. Create a dart file under `lib/route/` (or just duplicate a file, e.g. `cp widgets_icon_ex.dart new_example.dart`);
6+
2. In the new file, create an example widget;
7+
3. In `my_app_routes.dart`, add a new `MyRoute` entry, with `child` being the example widget from last step;
8+
4. Add other metadata like `sourceFilePath`,`title`, `description` and `links` to the `MyRoute` entry;
9+
5. test run the app;
10+
6. create a git pull request on github
11+
12+
13+
## app release
14+
15+
### Android
16+
17+
```sh
18+
# Copy dart defines to clipboard
19+
$ define_env -c
20+
# Build appbundle with the dart defines:
21+
$ flutter build --dart-define=...
22+
# Copy the built file to tmp/releases:
23+
$ cp build/app/outputs/bundle/release/app-release.aab \
24+
tmp/releases/releases.link/flutter_catalog_va.b.c+dd.aab
25+
```
26+
27+
### iOS
28+
```sh
29+
# Optional: re-install pod files
30+
$ cd ios && pod install --repo-update && cd ..
31+
# Copy dart defines to clipboard
32+
$ define_env -c
33+
# Build ipa with the dart defines:
34+
$ flutter build ipa --release --dart-define=...
35+
# Open the archive in XCode
36+
$ open build/ios/archive/Runner.xcarchive
37+
```

Diff for: README.md

-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ And note there are some [limitations](https://github.com/X-Wei/flutter_catalog/i
2727
<img src="screenshots/Screenshot_1546722852.png" width="240px" />
2828

2929

30-
## How to contribute by adding a new example page
31-
32-
1. Create a dart file under `lib/route/` (or just duplicate a file, e.g. `cp widgets_icon_ex.dart new_example.dart`);
33-
2. In the new file, create a class that extends MyRoute;
34-
3. Add constructor, the convention is to use the file path as constructor's default parameter;
35-
4. (Optional) override getters: `title`, `description`, `links`;
36-
5. Override `buildMyRouteContent()`, try to make the code simple, as it'll be shown on phone screens;
37-
6. Open `lib/my_app_meta.dart`, import the new file at the beginning of file;
38-
7. In `kMyAppRoutesStructure`, add an instantiation of the new class under the appropriate item group.
39-
4030
## Credits
4131

4232
This app is written with reference to many resources, including:

Diff for: lib/env.dart

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: lib/my_app_routes.dart

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import 'routes/multimedia_extended_image_ex.dart';
7474
import 'routes/multimedia_image_picker_ex.dart';
7575
import 'routes/multimedia_image_plugin_ex.dart';
7676
import 'routes/multimedia_video_player_ex.dart';
77+
import 'routes/multimedia_youtube_player_ex.dart';
7778
import 'routes/nav_bottom_navbar_ex.dart';
7879
import 'routes/nav_bottom_sheet_ex.dart';
7980
import 'routes/nav_bottom_tabbar_ex.dart';
@@ -777,6 +778,12 @@ const kMyAppRoutesAdvanced = <MyRouteGroup>[
777778
description: 'Video/audio player plugin by the flutter team.',
778779
links: {'Pub': 'https://pub.dev/packages/video_player'},
779780
),
781+
MyRoute(
782+
child: YoutubePlayerExample(),
783+
sourceFilePath: 'lib/routes/multimedia_youtube_player_ex.dart',
784+
title: 'Youtube Player',
785+
links: {'Pub': 'https://pub.dev/packages/youtube_player_iframe'},
786+
),
780787
MyRoute(
781788
child: EdgeDetectionExample(),
782789
sourceFilePath: 'lib/routes/multimedia_edge_detection_ex.dart',

Diff for: lib/routes/multimedia_youtube_player_ex.dart

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:youtube_player_iframe/youtube_player_iframe.dart';
3+
4+
class YoutubePlayerExample extends StatefulWidget {
5+
const YoutubePlayerExample({super.key});
6+
7+
@override
8+
State<YoutubePlayerExample> createState() => _YoutubePlayerExampleState();
9+
}
10+
11+
class _YoutubePlayerExampleState extends State<YoutubePlayerExample> {
12+
final _txtController = TextEditingController();
13+
//! Use `YoutubePlayerController.fromVideoId` if just play a single video.
14+
final _ytController = YoutubePlayerController(
15+
params: const YoutubePlayerParams(
16+
showFullscreenButton: true, mute: false, showControls: true),
17+
);
18+
19+
@override
20+
void initState() {
21+
super.initState();
22+
_txtController.text = 'https://www.youtube.com/watch?v=jfKfPfyJRdk';
23+
}
24+
25+
String? _getVideoId() {
26+
if (_txtController.text.startsWith('https://youtu.be/')) {
27+
return _txtController.text.substring('https://youtu.be/'.length);
28+
} else if (_txtController.text
29+
.startsWith('https://www.youtube.com/watch?v=')) {
30+
return _txtController.text
31+
.substring('https://www.youtube.com/watch?v='.length);
32+
}
33+
return null;
34+
}
35+
36+
Future<void> _play() async {
37+
final videoId = _getVideoId();
38+
if (videoId == null) {
39+
ScaffoldMessenger.of(context)
40+
..clearSnackBars()
41+
..showSnackBar(
42+
SnackBar(
43+
content: Text(
44+
'Failed to extract video Id from "${_txtController.text}"!\n'
45+
'Please make sure it is in either "https://youtu.be/\$id" or "https://www.youtube.com/watch?v=\$id" format!'),
46+
),
47+
);
48+
return;
49+
}
50+
//? loadVideoByUrl doesn't work?
51+
// await _ytController.loadVideoByUrl(mediaContentUrl: _txtController.text);
52+
await _ytController.loadVideoById(videoId: videoId);
53+
}
54+
55+
@override
56+
Widget build(BuildContext context) {
57+
// We can add the player along with other widgets with the YoutubePlayerScaffold
58+
return YoutubePlayerScaffold(
59+
builder: (ctx, player) => SingleChildScrollView(
60+
child: Column(
61+
children: [
62+
Text('YT player iframe'),
63+
TextField(controller: _txtController),
64+
ElevatedButton(onPressed: _play, child: Text('play')),
65+
player,
66+
],
67+
),
68+
),
69+
controller: _ytController,
70+
);
71+
}
72+
}

Diff for: pubspec.lock

+43-1
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ packages:
19121912
name: url_launcher
19131913
url: "https://pub.dartlang.org"
19141914
source: hosted
1915-
version: "6.1.6"
1915+
version: "6.1.7"
19161916
url_launcher_android:
19171917
dependency: transitive
19181918
description:
@@ -2032,6 +2032,34 @@ packages:
20322032
url: "https://pub.dartlang.org"
20332033
source: hosted
20342034
version: "1.2.0"
2035+
webview_flutter:
2036+
dependency: transitive
2037+
description:
2038+
name: webview_flutter
2039+
url: "https://pub.dartlang.org"
2040+
source: hosted
2041+
version: "4.0.1"
2042+
webview_flutter_android:
2043+
dependency: transitive
2044+
description:
2045+
name: webview_flutter_android
2046+
url: "https://pub.dartlang.org"
2047+
source: hosted
2048+
version: "3.1.1"
2049+
webview_flutter_platform_interface:
2050+
dependency: transitive
2051+
description:
2052+
name: webview_flutter_platform_interface
2053+
url: "https://pub.dartlang.org"
2054+
source: hosted
2055+
version: "2.0.1"
2056+
webview_flutter_wkwebview:
2057+
dependency: transitive
2058+
description:
2059+
name: webview_flutter_wkwebview
2060+
url: "https://pub.dartlang.org"
2061+
source: hosted
2062+
version: "3.0.2"
20352063
widget_with_codeview:
20362064
dependency: "direct main"
20372065
description:
@@ -2067,6 +2095,20 @@ packages:
20672095
url: "https://pub.dartlang.org"
20682096
source: hosted
20692097
version: "3.1.1"
2098+
youtube_player_iframe:
2099+
dependency: "direct main"
2100+
description:
2101+
name: youtube_player_iframe
2102+
url: "https://pub.dartlang.org"
2103+
source: hosted
2104+
version: "4.0.1"
2105+
youtube_player_iframe_web:
2106+
dependency: transitive
2107+
description:
2108+
name: youtube_player_iframe_web
2109+
url: "https://pub.dartlang.org"
2110+
source: hosted
2111+
version: "2.0.0"
20702112
sdks:
20712113
dart: ">=2.18.0 <3.0.0"
20722114
flutter: ">=3.3.0"

Diff for: pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_catalog
22
description: An app showcasing Flutter components, with side-by-side source code view.
33

4-
version: 3.5.2+93
4+
version: 3.5.3+95
55

66
environment:
77
sdk: ">=2.17.0 <3.0.0"
@@ -103,6 +103,7 @@ dependencies:
103103
url_launcher: ^6.0.9
104104
video_player: ^2.1.12
105105
widget_with_codeview: ^3.0.1
106+
youtube_player_iframe: ^4.0.1
106107

107108
dev_dependencies:
108109
build_runner: ^2.0.6

0 commit comments

Comments
 (0)