Protótipo Vilacorp
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:decpisos/index/index_controller.dart';
|
||||
import 'package:decpisos/videos/api/youtube_api.dart';
|
||||
import 'package:decpisos/videos/api/youtube_classes.dart';
|
||||
import 'package:vilacorp/index/index_controller.dart';
|
||||
import 'package:vilacorp/videos/api/youtube_api.dart';
|
||||
import 'package:vilacorp/videos/api/youtube_classes.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart' show DateFormat;
|
||||
|
||||
@@ -16,50 +16,61 @@ class YouTubeController extends GetxController {
|
||||
bool atualizar = false;
|
||||
var errorCode = 0.obs;
|
||||
String? errorMessage = '';
|
||||
var loading = true.obs;
|
||||
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,
|
||||
// ));
|
||||
|
||||
// _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.value.errorCode == 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();
|
||||
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.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!);
|
||||
} 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!.addAll(more.items!);
|
||||
}
|
||||
if(this.errorCode.value == -5){
|
||||
if (this.errorCode.value == -5) {
|
||||
this._ic.tabsWithoutVideos();
|
||||
}
|
||||
this.loading.value = false;
|
||||
@@ -76,12 +87,11 @@ class YouTubeController extends GetxController {
|
||||
this.getChannelVideosBloc();
|
||||
}
|
||||
|
||||
String getDateFormatada(String dt){
|
||||
String getDateFormatada(String dt) {
|
||||
String r = '';
|
||||
try {
|
||||
r = this.f.format(DateTime.parse(dt));
|
||||
} catch (e) {
|
||||
}
|
||||
} catch (e) {}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:decpisos/videos/youtube_video_player.dart';
|
||||
import 'package:vilacorp/videos/youtube_video_player.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -53,18 +53,18 @@ import 'bloc/youtube_controller.dart';
|
||||
// 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."),
|
||||
// ),);
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// )),
|
||||
// )),
|
||||
// );
|
||||
// }
|
||||
|
||||
@@ -102,7 +102,7 @@ import 'bloc/youtube_controller.dart';
|
||||
// // fullScreen: true //default false
|
||||
// // );
|
||||
// // },
|
||||
// // )
|
||||
// // )
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
@@ -168,7 +168,7 @@ import 'bloc/youtube_controller.dart';
|
||||
// RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
class YouTubeVideosScreen extends StatefulWidget {
|
||||
@@ -176,8 +176,8 @@ class YouTubeVideosScreen extends StatefulWidget {
|
||||
_YouTubeVideosScreenState createState() => _YouTubeVideosScreenState();
|
||||
}
|
||||
|
||||
class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with AutomaticKeepAliveClientMixin<YouTubeVideosScreen> {
|
||||
|
||||
class _YouTubeVideosScreenState extends State<YouTubeVideosScreen>
|
||||
with AutomaticKeepAliveClientMixin<YouTubeVideosScreen> {
|
||||
final YouTubeController c = Get.put(YouTubeController());
|
||||
|
||||
@override
|
||||
@@ -195,66 +195,74 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
|
||||
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."),
|
||||
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."),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
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)!){
|
||||
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,
|
||||
));
|
||||
}
|
||||
else{
|
||||
Get.to(() => YouTubeVideoPlayerScreen(ytVideo: item,));
|
||||
}
|
||||
|
||||
},
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
@@ -266,7 +274,7 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
|
||||
LimitedBox(
|
||||
maxHeight: 100.0,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 4/3,
|
||||
aspectRatio: 4 / 3,
|
||||
child: FadeInImage.memoryNetwork(
|
||||
placeholder: kTransparentImage,
|
||||
image: item.snippet?.thumbnails?.thumbDefault?.url ?? '',
|
||||
@@ -284,21 +292,24 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
|
||||
item.snippet!.title!,
|
||||
softWrap: true,
|
||||
maxLines: 2,
|
||||
style: TextStyle(fontSize: 13.0,fontWeight: FontWeight.bold),
|
||||
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),
|
||||
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),
|
||||
style:
|
||||
TextStyle(fontSize: 9.0, fontWeight: FontWeight.w300),
|
||||
),
|
||||
]))
|
||||
],
|
||||
@@ -308,7 +319,7 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildError(){
|
||||
Widget _buildError() {
|
||||
return Container(
|
||||
width: double.maxFinite,
|
||||
child: Column(
|
||||
@@ -321,5 +332,5 @@ class _YouTubeVideosScreenState extends State<YouTubeVideosScreen> with Automati
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user