carga inicial
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../funcoes_gerais.dart';
|
||||
import 'youtube_classes.dart';
|
||||
|
||||
class YouTubeApi{
|
||||
|
||||
Future<YouTubeSearchResponse> getChannelVideos({String nextPageToken = ''}) async {
|
||||
var retorno = new YouTubeSearchResponse(
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
etag: '',
|
||||
items: [],
|
||||
kind: '',
|
||||
nextPageToken: '',
|
||||
);
|
||||
|
||||
if (await FuncoesGerais.checkInternetConnection() == false) {
|
||||
retorno.errorCode = 1;
|
||||
retorno.errorMessage = "Sem conexão com a internet";
|
||||
return retorno;
|
||||
}
|
||||
|
||||
String url = "https://www.googleapis.com/youtube/v3/search?key=${FuncoesGerais.youtubeApiKey}&channelId=${FuncoesGerais.channelId}&part=snippet,id&order=date&maxResults=10";
|
||||
|
||||
if(nextPageToken.isNotEmpty) url += "&pageToken=$nextPageToken";
|
||||
|
||||
try{
|
||||
var response = await http.get(url);
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
retorno = YouTubeSearchResponse.fromJson(data);
|
||||
} else {
|
||||
var data = jsonDecode(response.body);
|
||||
retorno.errorCode = 2;
|
||||
retorno.errorMessage = "Erro inesperado, tente novamente mais tarde. #${response.statusCode}";
|
||||
if(data != null && data['error'] != null){
|
||||
if(data['error']['message'] != null && data['error']['message'].toString().isNotEmpty){
|
||||
retorno.errorMessage = data['error']['message'].toString();
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
} else {
|
||||
retorno.errorCode = 2;
|
||||
retorno.errorMessage = "Erro inesperado, tente novamente mais tarde";
|
||||
return retorno;
|
||||
}
|
||||
} catch (e) {
|
||||
retorno.errorCode = 2;
|
||||
retorno.errorMessage = "Falha interna no App, tente novamenre mais tarde.";
|
||||
return retorno;
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
class YouTubeSearchResponse {
|
||||
String kind;
|
||||
String etag;
|
||||
String nextPageToken;
|
||||
String regionCode;
|
||||
PageInfo pageInfo;
|
||||
List<YouTubeItems> items;
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
|
||||
YouTubeSearchResponse({this.kind, this.etag, this.nextPageToken, this.regionCode, this.pageInfo, this.items,this.errorCode = 0, this.errorMessage = ''});
|
||||
|
||||
YouTubeSearchResponse.fromJson(Map<String, dynamic> json) {
|
||||
kind = json['kind'] ?? '';
|
||||
etag = json['etag'] ?? '';
|
||||
nextPageToken = json['nextPageToken'] ?? '';
|
||||
regionCode = json['regionCode'] ?? '';
|
||||
pageInfo = json['pageInfo'] != null ? new PageInfo.fromJson(json['pageInfo']) : null;
|
||||
if (json['items'] != null) {
|
||||
items = new List<YouTubeItems>();
|
||||
json['items'].forEach((v) { items.add(new YouTubeItems.fromJson(v)); });
|
||||
}
|
||||
errorCode = 0;
|
||||
errorMessage = '';
|
||||
}
|
||||
}
|
||||
|
||||
class PageInfo {
|
||||
int totalResults;
|
||||
int resultsPerPage;
|
||||
|
||||
PageInfo({this.totalResults, this.resultsPerPage});
|
||||
|
||||
PageInfo.fromJson(Map<String, dynamic> json) {
|
||||
totalResults = json['totalResults'];
|
||||
resultsPerPage = json['resultsPerPage'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['totalResults'] = this.totalResults;
|
||||
data['resultsPerPage'] = this.resultsPerPage;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class YouTubeItems {
|
||||
String kind;
|
||||
String etag;
|
||||
Id id;
|
||||
Snippet snippet;
|
||||
|
||||
YouTubeItems({this.kind, this.etag, this.id, this.snippet});
|
||||
|
||||
YouTubeItems.fromJson(Map<String, dynamic> json) {
|
||||
kind = json['kind'];
|
||||
etag = json['etag'];
|
||||
id = json['id'] != null ? new Id.fromJson(json['id']) : null;
|
||||
snippet = json['snippet'] != null ? new Snippet.fromJson(json['snippet']) : null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['kind'] = this.kind;
|
||||
data['etag'] = this.etag;
|
||||
if (this.id != null) {
|
||||
data['id'] = this.id.toJson();
|
||||
}
|
||||
if (this.snippet != null) {
|
||||
data['snippet'] = this.snippet.toJson();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Id {
|
||||
String kind;
|
||||
String videoId;
|
||||
|
||||
Id({this.kind, this.videoId});
|
||||
|
||||
Id.fromJson(Map<String, dynamic> json) {
|
||||
kind = json['kind'];
|
||||
videoId = json['videoId'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['kind'] = this.kind;
|
||||
data['videoId'] = this.videoId;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Snippet {
|
||||
String publishedAt;
|
||||
String channelId;
|
||||
String title;
|
||||
String description;
|
||||
Thumbnails thumbnails;
|
||||
String channelTitle;
|
||||
String liveBroadcastContent;
|
||||
String publishTime;
|
||||
|
||||
Snippet({this.publishedAt, this.channelId, this.title, this.description, this.thumbnails, this.channelTitle, this.liveBroadcastContent, this.publishTime});
|
||||
|
||||
Snippet.fromJson(Map<String, dynamic> json) {
|
||||
publishedAt = json['publishedAt'];
|
||||
channelId = json['channelId'];
|
||||
title = json['title'];
|
||||
description = json['description'];
|
||||
thumbnails = json['thumbnails'] != null ? new Thumbnails.fromJson(json['thumbnails']) : null;
|
||||
channelTitle = json['channelTitle'];
|
||||
liveBroadcastContent = json['liveBroadcastContent'];
|
||||
publishTime = json['publishTime'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['publishedAt'] = this.publishedAt;
|
||||
data['channelId'] = this.channelId;
|
||||
data['title'] = this.title;
|
||||
data['description'] = this.description;
|
||||
if (this.thumbnails != null) {
|
||||
data['thumbnails'] = this.thumbnails.toJson();
|
||||
}
|
||||
data['channelTitle'] = this.channelTitle;
|
||||
data['liveBroadcastContent'] = this.liveBroadcastContent;
|
||||
data['publishTime'] = this.publishTime;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Thumbnails {
|
||||
ThumbDefault thumbDefault;
|
||||
ThumbDefault medium;
|
||||
ThumbDefault high;
|
||||
|
||||
Thumbnails({this.thumbDefault, this.medium, this.high});
|
||||
|
||||
Thumbnails.fromJson(Map<String, dynamic> json) {
|
||||
thumbDefault = json['default'] != null ? new ThumbDefault.fromJson(json['default']) : null;
|
||||
medium = json['medium'] != null ? new ThumbDefault.fromJson(json['medium']) : null;
|
||||
high = json['high'] != null ? new ThumbDefault.fromJson(json['high']) : null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
if (this.thumbDefault != null) {
|
||||
data['default'] = this.thumbDefault.toJson();
|
||||
}
|
||||
if (this.medium != null) {
|
||||
data['medium'] = this.medium.toJson();
|
||||
}
|
||||
if (this.high != null) {
|
||||
data['high'] = this.high.toJson();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class ThumbDefault {
|
||||
String url;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
ThumbDefault({this.url, this.width, this.height});
|
||||
|
||||
ThumbDefault.fromJson(Map<String, dynamic> json) {
|
||||
url = json['url'];
|
||||
width = json['width'];
|
||||
height = json['height'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['url'] = this.url;
|
||||
data['width'] = this.width;
|
||||
data['height'] = this.height;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:appcardsstarter/videos/api/youtube_api.dart';
|
||||
import 'package:appcardsstarter/videos/api/youtube_classes.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart' show DateFormat;
|
||||
|
||||
class YouTubeController extends GetxController {
|
||||
YouTubeApi _api = new YouTubeApi();
|
||||
|
||||
var results = new YouTubeSearchResponse(
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
items: [],
|
||||
).obs;
|
||||
var itens = <YouTubeItems>[].obs;
|
||||
bool atualizar = false;
|
||||
var errorCode = 0.obs;
|
||||
var errorMessage = '';
|
||||
var loading = true.obs;
|
||||
final f = DateFormat('dd/MM/yyyy HH:mm:ss');
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
||||
// _controller = AnimationController(
|
||||
// duration: const Duration(milliseconds: 650),
|
||||
// vsync: this,
|
||||
// )..forward();
|
||||
// animation = Tween<Offset>(
|
||||
// begin: const Offset(-0.5, 0.0),
|
||||
// end: const Offset(0.0, 0.0),
|
||||
// ).animate(CurvedAnimation(
|
||||
// parent: _controller,
|
||||
// curve: Curves.easeInCubic,
|
||||
// ));
|
||||
this.atualizar = true;
|
||||
this.itens = new RxList<YouTubeItems>();
|
||||
this.getChannelVideosBloc();
|
||||
}
|
||||
|
||||
Future<void> getChannelVideosBloc({String textoBusca = '-'}) async {
|
||||
//this.loading.value = true;
|
||||
if (results == null || atualizar || results.value.errorCode != 0) {
|
||||
results.value = new YouTubeSearchResponse();
|
||||
this.itens = new RxList<YouTubeItems>();
|
||||
results.value = await this._api.getChannelVideos();
|
||||
results.value.items = results.value.items.where((element) => GetUtils.isNullOrBlank(element.id.videoId) == false).toList();
|
||||
this.itens.addAll(results.value.items);
|
||||
this.errorCode.value = results.value.errorCode;
|
||||
this.errorMessage = results.value.errorMessage;
|
||||
this.atualizar = false;
|
||||
} else if (results.value.nextPageToken != null && results.value.nextPageToken.isNotEmpty) {
|
||||
var more = await this._api.getChannelVideos(nextPageToken: results.value.nextPageToken);
|
||||
more.items = more.items.where((element) => GetUtils.isNullOrBlank(element.id.videoId) == false).toList();
|
||||
this.errorCode.value = more.errorCode;
|
||||
this.errorMessage = more.errorMessage;
|
||||
this.itens.addAll(more.items);
|
||||
results.value.nextPageToken = more.nextPageToken ?? '';
|
||||
results.value.items += more.items;
|
||||
}
|
||||
this.loading.value = false;
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
this.loading.value = true;
|
||||
this.atualizar = true;
|
||||
results.value = YouTubeSearchResponse(
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
items: [],
|
||||
);
|
||||
this.getChannelVideosBloc();
|
||||
}
|
||||
|
||||
String getDateFormatada(String dt){
|
||||
String r = '';
|
||||
try {
|
||||
r = this.f.format(DateTime.parse(dt));
|
||||
} catch (e) {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_youtube_view/flutter_youtube_view.dart';
|
||||
|
||||
// class YoutubeCustomWidget extends StatefulWidget {
|
||||
// @override
|
||||
// _MyAppState createState() => _MyAppState();
|
||||
// }
|
||||
|
||||
// class _MyAppState extends State<YoutubeCustomWidget>
|
||||
// implements YouTubePlayerListener {
|
||||
// double _volume = 50;
|
||||
// double _videoDuration = 0.0;
|
||||
// double _currentVideoSecond = 0.0;
|
||||
// String _playerState = "";
|
||||
// FlutterYoutubeViewController _controller;
|
||||
// YoutubeScaleMode _mode = YoutubeScaleMode.none;
|
||||
// PlaybackRate _playbackRate = PlaybackRate.RATE_1;
|
||||
// bool _isMuted = false;
|
||||
|
||||
// @override
|
||||
// void onCurrentSecond(double second) {
|
||||
// // print("onCurrentSecond second = $second");
|
||||
// _currentVideoSecond = second;
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onError(String error) {
|
||||
// print("onError error = $error");
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onReady() {
|
||||
// print("onReady");
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onStateChange(String state) {
|
||||
// print("onStateChange state = $state");
|
||||
// setState(() {
|
||||
// _playerState = state;
|
||||
// });
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onVideoDuration(double duration) {
|
||||
// print("onVideoDuration duration = $duration");
|
||||
// }
|
||||
|
||||
// void _onYoutubeCreated(FlutterYoutubeViewController controller) {
|
||||
// this._controller = controller;
|
||||
// }
|
||||
|
||||
// void _loadOrCueVideo() {
|
||||
// _controller.loadOrCueVideo('gcj2RUWQZ60', _currentVideoSecond);
|
||||
// }
|
||||
|
||||
// void _play() {
|
||||
// _controller.play();
|
||||
// }
|
||||
|
||||
// void _pause() {
|
||||
// _controller.pause();
|
||||
// }
|
||||
|
||||
// void _seekTo(double time) {
|
||||
// _controller.seekTo(time);
|
||||
// }
|
||||
|
||||
// void _setVolume(int volumePercent) {
|
||||
// _controller.setVolume(volumePercent);
|
||||
// }
|
||||
|
||||
// void _changeScaleMode(YoutubeScaleMode mode) {
|
||||
// setState(() {
|
||||
// _mode = mode;
|
||||
// _controller.changeScaleMode(mode);
|
||||
// });
|
||||
// }
|
||||
|
||||
// void _changeVolumeMode(bool isMuted) {
|
||||
// setState(() {
|
||||
// _isMuted = isMuted;
|
||||
// if (isMuted) {
|
||||
// _controller.setMute();
|
||||
// } else {
|
||||
// _controller.setUnMute();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// void _changePlaybackRate(PlaybackRate playbackRate) {
|
||||
// setState(() {
|
||||
// _playbackRate = playbackRate;
|
||||
// _controller.setPlaybackRate(playbackRate);
|
||||
// });
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: const Text('Custom UI')
|
||||
// ),
|
||||
// body: Stack(
|
||||
// children: <Widget>[
|
||||
// Container(
|
||||
// child: FlutterYoutubeView(
|
||||
// scaleMode: _mode,
|
||||
// onViewCreated: _onYoutubeCreated,
|
||||
// listener: this,
|
||||
// params: YoutubeParam(
|
||||
// videoId: 'gcj2RUWQZ60',
|
||||
// showUI: false,
|
||||
// startSeconds: 0.0,
|
||||
// autoPlay: false,
|
||||
// ),
|
||||
// )),
|
||||
// Column(
|
||||
// children: <Widget>[
|
||||
// Text(
|
||||
// 'Current state: $_playerState',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// RaisedButton(
|
||||
// onPressed: _loadOrCueVideo,
|
||||
// child: Text('Click reload video'),
|
||||
// ),
|
||||
// _buildControl(),
|
||||
// _buildVolume(),
|
||||
// _buildScaleModeRadioGroup(),
|
||||
// _buildPlaybackRate()
|
||||
// ],
|
||||
// )
|
||||
// ],
|
||||
// ));
|
||||
// }
|
||||
|
||||
// Widget _buildControl() {
|
||||
// return new Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// children: <Widget>[
|
||||
// RaisedButton(
|
||||
// onPressed: _play,
|
||||
// child: Text('Play'),
|
||||
// ),
|
||||
// RaisedButton(
|
||||
// onPressed: _pause,
|
||||
// child: Text('Pause'),
|
||||
// ),
|
||||
// RaisedButton(
|
||||
// onPressed: () {
|
||||
// _seekTo(20.0);
|
||||
// },
|
||||
// child: Text('seekTo 20s'),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget _buildScaleModeRadioGroup() {
|
||||
// return new Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// new Radio(
|
||||
// value: YoutubeScaleMode.none,
|
||||
// groupValue: _mode,
|
||||
// onChanged: _changeScaleMode,
|
||||
// ),
|
||||
// new Text(
|
||||
// 'none',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: YoutubeScaleMode.fitWidth,
|
||||
// groupValue: _mode,
|
||||
// onChanged: _changeScaleMode,
|
||||
// ),
|
||||
// new Text(
|
||||
// 'fitWidth',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: YoutubeScaleMode.fitHeight,
|
||||
// groupValue: _mode,
|
||||
// onChanged: _changeScaleMode,
|
||||
// ),
|
||||
// new Text(
|
||||
// 'fitHeight',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget _buildVolume() {
|
||||
// return new Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// new Radio(
|
||||
// value: false,
|
||||
// groupValue: _isMuted,
|
||||
// onChanged: _changeVolumeMode,
|
||||
// ),
|
||||
// new Text(
|
||||
// 'unMute',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: true,
|
||||
// groupValue: _isMuted,
|
||||
// onChanged: _changeVolumeMode,
|
||||
// ),
|
||||
// new Text(
|
||||
// 'Mute',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget _buildPlaybackRate() {
|
||||
// return new Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// new Radio(
|
||||
// value: PlaybackRate.RATE_0_25,
|
||||
// groupValue: _playbackRate,
|
||||
// onChanged: _changePlaybackRate,
|
||||
// ),
|
||||
// new Text(
|
||||
// '0_25',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: PlaybackRate.RATE_0_5,
|
||||
// groupValue: _playbackRate,
|
||||
// onChanged: _changePlaybackRate,
|
||||
// ),
|
||||
// new Text(
|
||||
// '0_5',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: PlaybackRate.RATE_1,
|
||||
// groupValue: _playbackRate,
|
||||
// onChanged: _changePlaybackRate,
|
||||
// ),
|
||||
// new Text(
|
||||
// '1',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: PlaybackRate.RATE_1_5,
|
||||
// groupValue: _playbackRate,
|
||||
// onChanged: _changePlaybackRate,
|
||||
// ),
|
||||
// new Text(
|
||||
// '1_5',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// ),
|
||||
// new Radio(
|
||||
// value: PlaybackRate.RATE_2,
|
||||
// groupValue: _playbackRate,
|
||||
// onChanged: _changePlaybackRate,
|
||||
// ),
|
||||
// new Text(
|
||||
// '2',
|
||||
// style: TextStyle(color: Colors.blue),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,90 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_youtube_view/flutter_youtube_view.dart';
|
||||
|
||||
// class YoutubeDefaultWidget extends StatefulWidget {
|
||||
// final String id;
|
||||
// YoutubeDefaultWidget({this.id});
|
||||
// @override
|
||||
// _MyAppState createState() => _MyAppState();
|
||||
// }
|
||||
|
||||
// class _MyAppState extends State<YoutubeDefaultWidget>
|
||||
// implements YouTubePlayerListener {
|
||||
// //double _currentVideoSecond = 0.0;
|
||||
// //String _playerState = "";
|
||||
// //FlutterYoutubeViewController _controller;
|
||||
|
||||
// @override
|
||||
// void onCurrentSecond(double second) {
|
||||
// // print("onCurrentSecond second = $second");
|
||||
// // _currentVideoSecond = second;
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onError(String error) {
|
||||
// print("onError error = $error");
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onReady() {
|
||||
// print("onReady");
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onStateChange(String state) {
|
||||
// // print("onStateChange state = $state");
|
||||
// // setState(() {
|
||||
// // _playerState = state;
|
||||
// // });
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void onVideoDuration(double duration) {
|
||||
// print("onVideoDuration duration = $duration");
|
||||
// }
|
||||
|
||||
// void _onYoutubeCreated(FlutterYoutubeViewController controller) {
|
||||
// //this._controller = controller;
|
||||
// }
|
||||
|
||||
// // void _loadOrCueVideo() {
|
||||
// // _controller.loadOrCueVideo('gcj2RUWQZ60', _currentVideoSecond);
|
||||
// // }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(),
|
||||
// body: Stack(
|
||||
// children: <Widget>[
|
||||
// AspectRatio(
|
||||
// aspectRatio: 16/9,
|
||||
// child: FlutterYoutubeView(
|
||||
// onViewCreated: _onYoutubeCreated,
|
||||
// listener: this,
|
||||
// params: YoutubeParam(
|
||||
// videoId: widget.id,
|
||||
// showUI: true,
|
||||
// //startSeconds: 5 * 60.0,
|
||||
// autoPlay: true,
|
||||
// showYoutube: false,
|
||||
// showFullScreen: true,
|
||||
// ),
|
||||
// )),
|
||||
// // Center(
|
||||
// // child: Column(
|
||||
// // children: <Widget>[
|
||||
// // Text(
|
||||
// // 'Current state: $_playerState',
|
||||
// // style: TextStyle(color: Colors.blue),
|
||||
// // ),
|
||||
// // RaisedButton(
|
||||
// // onPressed: _loadOrCueVideo,
|
||||
// // child: Text('Click reload video'),
|
||||
// // ),
|
||||
// // ],
|
||||
// // ))
|
||||
// ],
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
||||
|
||||
import 'api/youtube_classes.dart';
|
||||
|
||||
class YouTubeVideoPlayerScreen extends StatefulWidget {
|
||||
final YouTubeItems ytVideo;
|
||||
YouTubeVideoPlayerScreen({@required this.ytVideo});
|
||||
@override
|
||||
_YouTubeVideoPlayerScreenState createState() => _YouTubeVideoPlayerScreenState();
|
||||
}
|
||||
|
||||
class _YouTubeVideoPlayerScreenState extends State<YouTubeVideoPlayerScreen> {
|
||||
|
||||
YoutubePlayerController _controller;
|
||||
bool _fullScreen = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = new YoutubePlayerController(initialVideoId: widget.ytVideo.id.videoId);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
//_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
//appBar: AppBar(),
|
||||
body: SafeArea(
|
||||
child: YoutubePlayerBuilder(
|
||||
player: YoutubePlayer(
|
||||
controller: _controller,
|
||||
topActions: [
|
||||
IconButton(icon: Icon(Icons.close),onPressed: (){
|
||||
if(this._fullScreen){
|
||||
_controller.toggleFullScreenMode();
|
||||
}
|
||||
else{
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
onEnterFullScreen: (){
|
||||
this._fullScreen = true;
|
||||
},
|
||||
onExitFullScreen: ()=>this._fullScreen = false,
|
||||
builder: (context,player){
|
||||
return Column(
|
||||
children: [
|
||||
player,
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(widget.ytVideo.snippet.title),
|
||||
SizedBox(height: 10.0,),
|
||||
Text(widget.ytVideo.snippet.description),
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
import 'package:appcardsstarter/videos/youtube_video_player.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:transparent_image/transparent_image.dart';
|
||||
|
||||
//import 'players/YoutubeCustomWidget.dart';
|
||||
import 'api/youtube_classes.dart';
|
||||
import 'bloc/youtube_controller.dart';
|
||||
//import 'players/YoutubeDefaultWidget.dart';
|
||||
|
||||
// class YouTubeVideosScreen extends StatelessWidget {
|
||||
// final YouTubeController c = Get.put(YouTubeController());
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text('Vídeos'),
|
||||
// ),
|
||||
// body: Obx(() => c.loading.value ? Center(child: CircularProgressIndicator(),) : c.errorCode.value != 0 ? this._buildError() : RefreshIndicator(
|
||||
// onRefresh: c.refresh,
|
||||
// child: AnimationLimiter(
|
||||
// child: ListView.builder(
|
||||
// padding: const EdgeInsets.all(8.0),
|
||||
// itemCount: c.itens.length + 1,
|
||||
// itemBuilder: (_,index){
|
||||
// if (index < c.itens.length) {
|
||||
// var item = c.itens[index];
|
||||
// return AnimationConfiguration.staggeredList(
|
||||
// position: index,
|
||||
// duration: const Duration(milliseconds: 375),
|
||||
// child: SlideAnimation(
|
||||
// verticalOffset: 30.0,
|
||||
// child: FadeInAnimation(
|
||||
// child: listItem(item),
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// // return SlideTransition(
|
||||
// // position: c.animation,
|
||||
// // child: this._buildListTile(index)
|
||||
// // );
|
||||
// } else if (index > 1) {
|
||||
// if (!GetUtils.isNullOrBlank(c.results.value.nextPageToken)) {
|
||||
// c.getChannelVideosBloc();
|
||||
// return Center(child: CircularProgressIndicator(),);
|
||||
// } else {
|
||||
// return Center(
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.only(top: 8.0,bottom: 25.0),
|
||||
// child:
|
||||
// Text("Não há mais Vídeos para exibir."),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// return Center(child: Padding(
|
||||
// padding: const EdgeInsets.only(top: 8.0),
|
||||
// child: Text("Não há mais Vídeos para exibir."),
|
||||
// ),);
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// )),
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget listItem(YouTubeItems item) {
|
||||
// return InkWell(
|
||||
// onTap: (){
|
||||
// showModalBottomSheet(context: Get.context, builder: (_)=>Container(
|
||||
// child: Column(
|
||||
// children: [
|
||||
// ListTile(
|
||||
// title: Text('Player 1'),
|
||||
// onTap: (){
|
||||
// Get.to(() => YouTubeVideoPlayerScreen(ytVideo: item,));
|
||||
// },
|
||||
// ),
|
||||
// // ListTile(
|
||||
// // title: Text('Player 2 - YoutubeDefaultWidget'),
|
||||
// // onTap: (){
|
||||
// // Navigator.of(context).push(MaterialPageRoute(builder: (_)=>YoutubeDefaultWidget(id: item.id.videoId)));
|
||||
// // },
|
||||
// // ),
|
||||
// // ListTile(
|
||||
// // title: Text('Player 3 - YoutubeCustomWidget'),
|
||||
// // onTap: (){
|
||||
// // Navigator.of(context).push(MaterialPageRoute(builder: (_)=>YoutubeCustomWidget()));
|
||||
// // },
|
||||
// // ),
|
||||
// // ListTile(
|
||||
// // title: Text('Player 3 - API key'),
|
||||
// // onTap: (){
|
||||
// // FlutterYoutube.playYoutubeVideoById(
|
||||
// // apiKey:FuncoesGerais.youtubeApiKey,
|
||||
// // videoId: item.id.videoId,
|
||||
// // autoPlay: true, //default falase
|
||||
// // fullScreen: true //default false
|
||||
// // );
|
||||
// // },
|
||||
// // )
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
// },
|
||||
// child: Card(
|
||||
// elevation: 0,
|
||||
// color: Colors.transparent,
|
||||
// child: Container(
|
||||
// //margin: EdgeInsets.only(bottom: 8.0),
|
||||
// child: Row(
|
||||
// children: <Widget>[
|
||||
// LimitedBox(
|
||||
// maxHeight: 100.0,
|
||||
// child: AspectRatio(
|
||||
// aspectRatio: 4/3,
|
||||
// child: FadeInImage.memoryNetwork(
|
||||
// placeholder: kTransparentImage,
|
||||
// image: item.snippet?.thumbnails?.thumbDefault?.url ?? '',
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Padding(padding: EdgeInsets.only(right: 10.0)),
|
||||
// Expanded(
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: <Widget>[
|
||||
// Text(
|
||||
// item.snippet.title,
|
||||
// softWrap: true,
|
||||
// maxLines: 2,
|
||||
// style: TextStyle(fontSize: 13.0,fontWeight: FontWeight.bold),
|
||||
// ),
|
||||
// Padding(padding: EdgeInsets.only(bottom: 1.5)),
|
||||
// Text(
|
||||
// item.snippet.description,
|
||||
// softWrap: true,
|
||||
// maxLines: 3,
|
||||
// style: TextStyle(fontSize: 11.0,fontWeight: FontWeight.w400),
|
||||
// ),
|
||||
// Padding(padding: EdgeInsets.only(bottom: 3.0)),
|
||||
// Text(
|
||||
// item.snippet.publishedAt,
|
||||
// softWrap: true,
|
||||
// maxLines: 1,
|
||||
// style: TextStyle(fontSize: 9.0,fontWeight: FontWeight.w300),
|
||||
// ),
|
||||
// ]))
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget _buildError(){
|
||||
// return Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// Text(c.errorMessage),
|
||||
// RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
class YouTubeVideosScreen extends StatefulWidget {
|
||||
@override
|
||||
_YouTubeVideosScreenState createState() => _YouTubeVideosScreenState();
|
||||
}
|
||||
|
||||
class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with AutomaticKeepAliveClientMixin<YouTubeVideosScreen> {
|
||||
|
||||
final YouTubeController c = Get.put(YouTubeController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Vídeos'),
|
||||
),
|
||||
body: Obx(() => c.loading.value ? Center(child: CircularProgressIndicator(),) : c.errorCode.value != 0 ? this._buildError() : RefreshIndicator(
|
||||
onRefresh: c.refresh,
|
||||
child: AnimationLimiter(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
itemCount: c.itens.length + 1,
|
||||
itemBuilder: (_,index){
|
||||
if (index < c.itens.length) {
|
||||
var item = c.itens[index];
|
||||
return AnimationConfiguration.staggeredList(
|
||||
position: index,
|
||||
duration: const Duration(milliseconds: 375),
|
||||
child: SlideAnimation(
|
||||
verticalOffset: 30.0,
|
||||
child: FadeInAnimation(
|
||||
child: listItem(item),
|
||||
)
|
||||
)
|
||||
);
|
||||
// return SlideTransition(
|
||||
// position: c.animation,
|
||||
// child: this._buildListTile(index)
|
||||
// );
|
||||
} else if (index > 1) {
|
||||
if (!GetUtils.isNullOrBlank(c.results.value.nextPageToken)) {
|
||||
c.getChannelVideosBloc();
|
||||
return Center(child: CircularProgressIndicator(),);
|
||||
} else {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0,bottom: 25.0),
|
||||
child:
|
||||
Text("Não há mais Vídeos para exibir."),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return Center(child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text("Não há mais Vídeos para exibir."),
|
||||
),);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget listItem(YouTubeItems item) {
|
||||
return InkWell(
|
||||
onTap: (){
|
||||
if(GetUtils.isNullOrBlank(item.id.videoId)){
|
||||
Get.rawSnackbar(message: 'Não foi possível reproduzir o vídeo');
|
||||
}
|
||||
else{
|
||||
Get.to(() => YouTubeVideoPlayerScreen(ytVideo: item,));
|
||||
}
|
||||
|
||||
},
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
color: Colors.transparent,
|
||||
child: Container(
|
||||
//margin: EdgeInsets.only(bottom: 8.0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LimitedBox(
|
||||
maxHeight: 100.0,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 4/3,
|
||||
child: FadeInImage.memoryNetwork(
|
||||
placeholder: kTransparentImage,
|
||||
image: item.snippet?.thumbnails?.thumbDefault?.url ?? '',
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(right: 10.0)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
item.snippet.title,
|
||||
softWrap: true,
|
||||
maxLines: 2,
|
||||
style: TextStyle(fontSize: 13.0,fontWeight: FontWeight.bold),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(bottom: 1.5)),
|
||||
Text(
|
||||
item.snippet.description,
|
||||
softWrap: true,
|
||||
maxLines: 3,
|
||||
style: TextStyle(fontSize: 11.0,fontWeight: FontWeight.w400),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(bottom: 3.0)),
|
||||
Text(
|
||||
c.getDateFormatada(item.snippet.publishedAt),
|
||||
softWrap: true,
|
||||
maxLines: 1,
|
||||
style: TextStyle(fontSize: 9.0,fontWeight: FontWeight.w300),
|
||||
),
|
||||
]))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildError(){
|
||||
return Container(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(c.errorMessage),
|
||||
RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user