migração flutter 2.2.1

This commit is contained in:
Renan
2021-06-01 16:52:01 -03:00
parent c44fcdddea
commit dd6bbb650b
25 changed files with 568 additions and 469 deletions
+5 -4
View File
@@ -7,7 +7,7 @@ import 'youtube_classes.dart';
class YouTubeApi{
Future<YouTubeSearchResponse> getChannelVideos({String nextPageToken = ''}) async {
Future<YouTubeSearchResponse> getChannelVideos({String? nextPageToken = ''}) async {
var retorno = new YouTubeSearchResponse(
errorCode: 0,
errorMessage: '',
@@ -25,12 +25,13 @@ class YouTubeApi{
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";
if(nextPageToken!.isNotEmpty) url += "&pageToken=$nextPageToken";
try{
var response = await http.get(url);
var response = await http.get(Uri.parse(url));
if (response != null) {
//if (response != null) {
if (response.body.isNotEmpty) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
retorno = YouTubeSearchResponse.fromJson(data);
+38 -38
View File
@@ -1,12 +1,12 @@
class YouTubeSearchResponse {
String kind;
String etag;
String nextPageToken;
String regionCode;
PageInfo pageInfo;
List<YouTubeItems> items;
int errorCode;
String errorMessage;
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 = ''});
@@ -17,8 +17,8 @@ class YouTubeSearchResponse {
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)); });
items = <YouTubeItems>[];
json['items'].forEach((v) { items!.add(new YouTubeItems.fromJson(v)); });
}
errorCode = 0;
errorMessage = '';
@@ -26,8 +26,8 @@ class YouTubeSearchResponse {
}
class PageInfo {
int totalResults;
int resultsPerPage;
int? totalResults;
int? resultsPerPage;
PageInfo({this.totalResults, this.resultsPerPage});
@@ -45,10 +45,10 @@ class PageInfo {
}
class YouTubeItems {
String kind;
String etag;
Id id;
Snippet snippet;
String? kind;
String? etag;
Id? id;
Snippet? snippet;
YouTubeItems({this.kind, this.etag, this.id, this.snippet});
@@ -64,18 +64,18 @@ class YouTubeItems {
data['kind'] = this.kind;
data['etag'] = this.etag;
if (this.id != null) {
data['id'] = this.id.toJson();
data['id'] = this.id!.toJson();
}
if (this.snippet != null) {
data['snippet'] = this.snippet.toJson();
data['snippet'] = this.snippet!.toJson();
}
return data;
}
}
class Id {
String kind;
String videoId;
String? kind;
String? videoId;
Id({this.kind, this.videoId});
@@ -93,14 +93,14 @@ class Id {
}
class Snippet {
String publishedAt;
String channelId;
String title;
String description;
Thumbnails thumbnails;
String channelTitle;
String liveBroadcastContent;
String publishTime;
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});
@@ -122,7 +122,7 @@ class Snippet {
data['title'] = this.title;
data['description'] = this.description;
if (this.thumbnails != null) {
data['thumbnails'] = this.thumbnails.toJson();
data['thumbnails'] = this.thumbnails!.toJson();
}
data['channelTitle'] = this.channelTitle;
data['liveBroadcastContent'] = this.liveBroadcastContent;
@@ -132,9 +132,9 @@ class Snippet {
}
class Thumbnails {
ThumbDefault thumbDefault;
ThumbDefault medium;
ThumbDefault high;
ThumbDefault? thumbDefault;
ThumbDefault? medium;
ThumbDefault? high;
Thumbnails({this.thumbDefault, this.medium, this.high});
@@ -147,22 +147,22 @@ class Thumbnails {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.thumbDefault != null) {
data['default'] = this.thumbDefault.toJson();
data['default'] = this.thumbDefault!.toJson();
}
if (this.medium != null) {
data['medium'] = this.medium.toJson();
data['medium'] = this.medium!.toJson();
}
if (this.high != null) {
data['high'] = this.high.toJson();
data['high'] = this.high!.toJson();
}
return data;
}
}
class ThumbDefault {
String url;
int width;
int height;
String? url;
int? width;
int? height;
ThumbDefault({this.url, this.width, this.height});
+10 -10
View File
@@ -15,7 +15,7 @@ class YouTubeController extends GetxController {
var itens = <YouTubeItems>[].obs;
bool atualizar = false;
var errorCode = 0.obs;
var errorMessage = '';
String? errorMessage = '';
var loading = true.obs;
final f = DateFormat('dd/MM/yyyy HH:mm:ss');
@@ -41,23 +41,23 @@ class YouTubeController extends GetxController {
Future<void> getChannelVideosBloc({String textoBusca = '-'}) async {
//this.loading.value = true;
if (results == null || atualizar || results.value.errorCode != 0) {
if (results.value.errorCode == 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;
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) {
} 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;
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);
this.itens.addAll(more.items!);
results.value.nextPageToken = more.nextPageToken ?? '';
results.value.items += more.items;
results.value.items!.addAll(more.items!);
}
if(this.errorCode.value == -5){
this._ic.tabsWithoutVideos();
+5 -5
View File
@@ -5,19 +5,19 @@ import 'api/youtube_classes.dart';
class YouTubeVideoPlayerScreen extends StatefulWidget {
final YouTubeItems ytVideo;
YouTubeVideoPlayerScreen({@required this.ytVideo});
YouTubeVideoPlayerScreen({required this.ytVideo});
@override
_YouTubeVideoPlayerScreenState createState() => _YouTubeVideoPlayerScreenState();
}
class _YouTubeVideoPlayerScreenState extends State<YouTubeVideoPlayerScreen> {
YoutubePlayerController _controller;
late YoutubePlayerController _controller;
bool _fullScreen = false;
@override
void initState() {
super.initState();
_controller = new YoutubePlayerController(initialVideoId: widget.ytVideo.id.videoId);
_controller = new YoutubePlayerController(initialVideoId: widget.ytVideo.id!.videoId!);
}
@override
@@ -58,9 +58,9 @@ class _YouTubeVideoPlayerScreenState extends State<YouTubeVideoPlayerScreen> {
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text(widget.ytVideo.snippet.title),
Text(widget.ytVideo.snippet!.title!),
SizedBox(height: 10.0,),
Text(widget.ytVideo.snippet.description),
Text(widget.ytVideo.snippet!.description!),
],
),
)
+8 -7
View File
@@ -219,7 +219,7 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
// child: this._buildListTile(index)
// );
} else if (index > 1) {
if (!GetUtils.isNullOrBlank(c.results.value.nextPageToken)) {
if (!GetUtils.isNullOrBlank(c.results.value.nextPageToken)!) {
c.getChannelVideosBloc();
return Center(child: CircularProgressIndicator(),);
} else {
@@ -248,7 +248,7 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
Widget listItem(YouTubeItems item) {
return InkWell(
onTap: (){
if(GetUtils.isNullOrBlank(item.id.videoId)){
if(GetUtils.isNullOrBlank(item.id!.videoId)!){
Get.rawSnackbar(message: 'Não foi possível reproduzir o vídeo');
}
else{
@@ -281,21 +281,21 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
item.snippet.title,
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,
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),
c.getDateFormatada(item.snippet!.publishedAt!),
softWrap: true,
maxLines: 1,
style: TextStyle(fontSize: 9.0,fontWeight: FontWeight.w300),
@@ -315,8 +315,9 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(c.errorMessage),
RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
Text(c.errorMessage!),
ElevatedButton(onPressed: c.refresh, child: Text('Atualizar'))
//RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
],
),
);