-
Notifications
You must be signed in to change notification settings - Fork 3
/
shorts_by_video_url.dart
239 lines (223 loc) · 7.31 KB
/
shorts_by_video_url.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import 'package:flutter/material.dart';
import 'package:youtube_shorts/youtube_shorts.dart';
class ShortsByVideoUrl extends StatefulWidget {
const ShortsByVideoUrl({super.key});
@override
State<ShortsByVideoUrl> createState() => _ShortsByVideoUrlState();
}
class _ShortsByVideoUrlState extends State<ShortsByVideoUrl> {
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();
final TextEditingController _textEditingController = TextEditingController();
@override
void dispose() {
super.dispose();
_textEditingController.dispose();
}
List<String> links = [
'https://www.youtube.com/shorts/PiWJWfzVwjU', // 0
'https://www.youtube.com/shorts/AeZ3dmC676c', // 1
'https://www.youtube.com/shorts/L1lg_lxUxfw', // 2
'https://www.youtube.com/shorts/OWPsdhLHK7c', // 3
'https://www.youtube.com/shorts/GoQhFyoZxRM', // 4
'https://www.youtube.com/shorts/pzpp3PkVI-s', // 5
'https://www.youtube.com/shorts/Z9yyWrbonRs', // 6
'https://www.youtube.com/shorts/LPm0LUBxnRQ', // 7
'https://www.youtube.com/shorts/sG0lMuv88yg', // 8
'https://www.youtube.com/shorts/HEwvgMxsLcI', // 9
'https://www.youtube.com/shorts/8I1Gq1xW8L4', // 10
'https://www.youtube.com/shorts/tL7D5bivyH4', // 11
'https://www.youtube.com/shorts/7TVj_KqJ0wY', // 12
'https://www.youtube.com/shorts/GYqF_LXFlyg', // 13
'https://www.youtube.com/shorts/Il5rxWOw4GI', // 14
'https://www.youtube.com/shorts/a3XT1p7Uczk', // 15
'https://www.youtube.com/shorts/1S-c0yLCsNo', // 16
'https://www.youtube.com/shorts/S23UPbRai-w', // 17
'https://www.youtube.com/shorts/ZCDU4O1jnTo', // 18
];
bool seeHorizontalVideos = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('By url list'),
actions: [
IconButton(
onPressed: () {
if (links.isEmpty) {
links.clear();
setState(() {});
}
},
icon: const Icon(Icons.delete),
tooltip: 'Delete all fields',
),
],
),
body: Column(
children: [
const SizedBox(height: 8),
Text(
'Type the urls you want\nto play in stories',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 16),
Expanded(
child: ListView.builder(
itemCount: links.length,
itemBuilder: (context, index) {
final String link = links[index];
return ListTile(
title: Text(link),
trailing: IconButton(
onPressed: () {
links.remove(link);
setState(() {});
},
icon: const Icon(Icons.delete),
),
);
},
),
),
const SizedBox(height: 16),
Form(
key: _formkey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: TextFormField(
controller: _textEditingController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
final linkUrl = RegExp(
r'https://www.youtube.com/shorts/[a-zA-Z0-9]+',
);
if (linkUrl.hasMatch(value) == false) {
return 'Is not a youtube short url';
}
return null;
},
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: 'Type the youtube SHORTS link',
// labelText: 'Type the youtube channel name or id',
suffixIcon: IconButton(
onPressed: () {
final isValid = _formkey.currentState?.validate() == true;
if (isValid) {
links.add(_textEditingController.text);
setState(() {});
}
},
icon: const Icon(Icons.add),
),
),
),
),
),
const SizedBox(height: 8),
SwitchListTile.adaptive(
title: const Text('See horizontal videos widget'),
value: seeHorizontalVideos,
onChanged: (_) {
setState(() {
seeHorizontalVideos = !seeHorizontalVideos;
});
},
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: () {
if (_textEditingController.text.isNotEmpty) {
final isValid = _formkey.currentState?.validate() == true;
if (isValid == false) return;
}
final ids = links.map(
(v) => v.replaceAll('https://www.youtube.com/shorts/', ''),
);
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return ShortsByVideoUrlDisplay(
ids: ids.toList(),
seeHorizontalVideos: seeHorizontalVideos,
);
},
),
);
},
child: const Text('Start shorts view'),
),
const SizedBox(height: 40),
],
),
);
}
}
class ShortsByVideoUrlDisplay extends StatefulWidget {
final List<String> ids;
final bool seeHorizontalVideos;
const ShortsByVideoUrlDisplay({
super.key,
required this.ids,
required this.seeHorizontalVideos,
});
@override
State<ShortsByVideoUrlDisplay> createState() =>
_ShortsByVideoStateUrlDisplay();
}
class _ShortsByVideoStateUrlDisplay extends State<ShortsByVideoUrlDisplay> {
late final ShortsController controller;
@override
void initState() {
super.initState();
controller = ShortsController(
youtubeVideoSourceController: VideosSourceController.fromUrlList(
videoIds: widget.ids,
),
);
}
@override
Widget build(BuildContext context) {
if (widget.seeHorizontalVideos) {
return Scaffold(
body: Center(
child: YoutubeShortsHorizontalStoriesSection(
shortsPreviewHeight: 295,
controller: controller,
),
),
);
} else {
return YoutubeShortsPage(
controller: controller,
overlayWidgetBuilder: (
int index,
PageController pageController,
VideoController videoController,
Video videoData,
MuxedStreamInfo hostedVideoUrl,
) {
return Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(top: 100, left: 16),
child: CircleAvatar(
child: Text('$index'),
),
),
);
},
);
}
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}