carga inicial

This commit is contained in:
2021-05-04 16:12:48 -03:00
commit dbf070041b
88 changed files with 4809 additions and 0 deletions
+159
View File
@@ -0,0 +1,159 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../../default_response_api.dart';
import '../../funcoes_gerais.dart';
import 'notificacoes_classes.dart';
class NotificacoesApi{
Future<NotificacoesResponse> getNotificacoes(int pagina,{String lidas = 'T',String curtidas = 'T'}) async{
var retorno = new NotificacoesResponse(
errorCode: 0,
errorMessage: "",
loadMore: false,
results: []
);
if(await FuncoesGerais.checkInternetConnection() == false){
retorno.errorCode = 1;
retorno.errorMessage = "Sem conexão com a Internet";
}
else{
var token = await FuncoesGerais.getUsuToken();
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacoes/$token/$pagina/10/$lidas/$curtidas';
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var response = await http.get(url, headers: heads);
if (response != null) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
retorno = NotificacoesResponse.fromJson(data);
}
else{
retorno.errorCode = response.statusCode;
retorno.errorMessage = "Falha: ${response.statusCode}";
}
}
else{
retorno.errorCode = 2;
retorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
}
}
return retorno;
}
Future<NotificacaoResponse> getNotificacao(int id) async{
var retorno = new NotificacaoResponse(
errorCode: 0,
errorMessage: ""
);
if(await FuncoesGerais.checkInternetConnection() == false){
retorno.errorCode = 1;
retorno.errorMessage = "Sem conexão com a Internet";
}
else{
var token = await FuncoesGerais.getUsuToken();
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacao/$token/$id';
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var response = await http.get(url, headers: heads);
if (response != null) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
retorno = NotificacaoResponse.fromJson(data);
}
else{
retorno.errorCode = response.statusCode;
retorno.errorMessage = "Falha: ${response.statusCode}";
}
}
else{
retorno.errorCode = 2;
retorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
}
}
return retorno;
}
Future<DefaultResponseApi> notificacaoLike(NotificacaoLikeRequest post) async{
DefaultResponseApi objRetorno = new DefaultResponseApi();
if(await FuncoesGerais.checkInternetConnection() == false){
objRetorno.errorCode = 1;
objRetorno.errorMessage = "Sem Conexão com a Internet.";
return objRetorno;
}
var token = await FuncoesGerais.getUsuToken();
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacaolike/$token';
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var body = json.encode(post);
var response = await http.post(url, headers: heads, body: body);
if (response != null) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
objRetorno = DefaultResponseApi.fromJson(data);
}
else{
objRetorno.errorCode = response.statusCode;
objRetorno.errorMessage = "Falha: ${response.statusCode}";
}
}
else{
objRetorno.errorCode = 2;
objRetorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
}
return objRetorno;
}
Future<DefaultResponseApi> notificacaoLida(NotificacaoLidaRequest post, int notificacaoId) async{
DefaultResponseApi objRetorno = new DefaultResponseApi();
if(await FuncoesGerais.checkInternetConnection() == false){
objRetorno.errorCode = 1;
objRetorno.errorMessage = "Sem Conexão com a Internet.";
return objRetorno;
}
var token = await FuncoesGerais.getUsuToken();
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacaolida/$token/$notificacaoId';
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var body = json.encode(post);
var response = await http.post(url, headers: heads, body: body);
if (response != null) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
objRetorno = DefaultResponseApi.fromJson(data);
}
else{
objRetorno.errorCode = response.statusCode;
objRetorno.errorMessage = "Falha: ${response.statusCode}";
}
}
else{
objRetorno.errorCode = 2;
objRetorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
}
return objRetorno;
}
}
@@ -0,0 +1,142 @@
class NotificacaoLikeRequest {
int iD;
String like;
NotificacaoLikeRequest({this.iD, this.like});
NotificacaoLikeRequest.fromJson(Map<String, dynamic> json) {
iD = json['ID'];
like = json['Like'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ID'] = this.iD;
data['Like'] = this.like;
return data;
}
}
class NotificacaoLidaRequest {
String latitude;
String longitude;
NotificacaoLidaRequest({this.latitude, this.longitude});
NotificacaoLidaRequest.fromJson(Map<String, dynamic> json) {
latitude = json['Latitude'];
longitude = json['Longitude'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['Latitude'] = this.latitude;
data['Longitude'] = this.longitude;
return data;
}
}
class NotificacaoResponse {
NotificacaoResults result;
int errorCode;
String errorMessage;
NotificacaoResponse({this.result, this.errorCode, this.errorMessage});
NotificacaoResponse.fromJson(Map<String, dynamic> json) {
result =
json['Result'] != null ? new NotificacaoResults.fromJson(json['Result']) : null;
errorCode = json['ErrorCode'];
errorMessage = json['ErrorMessage'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.result != null) {
data['Result'] = this.result.toJson();
}
data['ErrorCode'] = this.errorCode;
data['ErrorMessage'] = this.errorMessage;
return data;
}
}
class NotificacoesResponse {
List<NotificacaoResults> results;
int errorCode;
String errorMessage;
bool loadMore;
NotificacoesResponse({this.results, this.errorCode, this.errorMessage,this.loadMore});
NotificacoesResponse.fromJson(Map<String, dynamic> json) {
if (json['Results'] != null) {
results = new List<NotificacaoResults>();
json['Results'].forEach((v) {
results.add(new NotificacaoResults.fromJson(v));
});
}
errorCode = json['ErrorCode'];
errorMessage = json['ErrorMessage'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.results != null) {
data['Results'] = this.results.map((v) => v.toJson()).toList();
}
data['ErrorCode'] = this.errorCode;
data['ErrorMessage'] = this.errorMessage;
return data;
}
}
class NotificacaoResults {
int iD;
String titulo;
String texto;
String conteudo;
String dataNotificacao;
String tipoConteudo;
bool visualizado;
String imageUrl;
String like;
NotificacaoResults(
{this.iD,
this.titulo,
this.texto,
this.conteudo,
this.dataNotificacao,
this.tipoConteudo,
this.visualizado,
this.imageUrl,
this.like = ''});
NotificacaoResults.fromJson(Map<String, dynamic> json) {
iD = json['ID'];
titulo = json['Titulo'] ?? '';
texto = json['Texto'];
conteudo = json['Conteudo'];
dataNotificacao = json['DataNotificacao'];
tipoConteudo = json['TipoConteudo'];
visualizado = json['Visualizado'];
imageUrl = json['ImageUrl'];
like = json['Like'] ?? '';
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['ID'] = this.iD;
data['Titulo'] = this.titulo;
data['Texto'] = this.texto;
data['Conteudo'] = this.conteudo;
data['DataNotificacao'] = this.dataNotificacao;
data['TipoConteudo'] = this.tipoConteudo;
data['Visualizado'] = this.visualizado;
data['ImageUrl'] = this.imageUrl;
data['Like'] = this.like;
return data;
}
}
+63
View File
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'notificacoes_controller.dart';
class NotificacaoDetail extends StatelessWidget {
final NotificacoesController c = Get.find();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
//
//title: Obx(() => Text(c.notificacaoDetail.value.result.titulo ?? 'Notificação')),
),
body: Obx(() => c.loadingDetail.value ? Center(child: CircularProgressIndicator(),) : c.notificacaoDetail.value.errorCode != 0 ? Center(child: Text(c.notificacaoDetail.value.errorMessage),) : ListView(
children: <Widget>[
Visibility(
visible: GetUtils.isNullOrBlank(c.notificacaoDetail.value.result.imageUrl) == false,
child: Container(
color: Colors.black38,
height: 250,
child: Padding(
padding: const EdgeInsets.all(70.0),
child: Image.network(
c.notificacaoDetail.value.result.imageUrl ?? '',
fit: BoxFit.contain,
),
),
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
c.notificacaoDetail.value.result.titulo,
style: TextStyle(fontSize: 30.0,),
),
const SizedBox(height: 10),
Html(
data: c.notificacaoDetail.value.result.conteudo,
onLinkTap: (url){
launch(url);
},
// style: Theme.of(context).textTheme.bodyText2.copyWith(
// color: Colors.black54,
// height: 1.5,
// fontSize: 16.0,
// ),
),
],
),
),
],
),
),
);
}
}
+168
View File
@@ -0,0 +1,168 @@
import 'package:flutter/material.dart';
import 'package:animations/animations.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import 'notificacao.dart';
import 'notificacoes_controller.dart';
//import 'package:supercharged/supercharged.dart';
class NotificacoesScreen extends StatelessWidget {
final NotificacoesController c = Get.put(NotificacoesController());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Notificações'),
centerTitle: false,
),
body: Obx(() => c.loading.value ? Center(child: CircularProgressIndicator(),) : c.errorCode.value != 0 ? this._buildError() : RefreshIndicator(
onRefresh: c.refresh,
// child: AnimatedList(
// key: c.listKey,
// padding: const EdgeInsets.all(8.0),
// initialItemCount: c.notificacoesResults.length + 1,
// itemBuilder: (context,index,animation){
// if (index < c.notificacoesResults.length) {
// return SlideTransition(
// //position: c.animation,
// position: Tween<Offset>(
// begin: const Offset(-1, 0),
// end: Offset(0, 0),
// ).animate(animation),
// child: this._buildListTile(index)
// );
// } else if (index > 1) {
// if(c.loadMore == null || c.loadMore){
// c.getNotificacoesBloc();
// return Container(
// height: 40,
// width: 40,
// alignment: Alignment.center,
// child: CircularProgressIndicator(),
// );
// }
// else{
// return Center(child: Padding(
// padding: const EdgeInsets.only(top: 8.0),
// child: Text("Não há mais Notificações para exibir."),
// ),);
// }
// }
// else {
// return Center(child: Padding(
// padding: const EdgeInsets.only(top: 8.0),
// child: Text("Não há mais Notificações para exibir."),
// ),);
// }
// }
// ),
child: ListView.builder(
padding: const EdgeInsets.all(8.0),
itemCount: c.notificacoesResults.length + 1,
itemBuilder: (_,index){
if (index < c.notificacoesResults.length) {
return this._buildListTile(index);
// return SlideTransition(
// position: c.animation,
// child: this._buildListTile(index)
// );
} else if (index > 1) {
if(c.loadMore == null || c.loadMore){
c.getNotificacoesBloc();
return Container(
height: 40,
width: 40,
alignment: Alignment.center,
child: CircularProgressIndicator(),
);
}
else{
return Center(child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text("Não há mais Notificações para exibir."),
),);
}
}
else {
return Center(child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text("Não há mais Notificações para exibir."),
),);
}
},
),
)),
// body: ListView(
// padding: const EdgeInsets.all(8.0),
// children: <Widget>[
// ...List<Widget>.generate(10, (int index) {
// return this._buildListTile(index);
// }),
// ],
// ),
);
}
Widget _buildError(){
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(c.errorMessage),
RaisedButton(onPressed: c.refresh, child: Text('Atualizar'),)
],
),
);
}
Widget _buildListTile(int index) {
if(c.notificacoesResults[index].tipoConteudo == 'L'){
return this._buildListTileTile(index: index,onTap: (){
c.notificacaoLidaBloc(c.notificacoesResults[index].iD).then((value) => launch(c.notificacoesResults[index].conteudo));
});
}
return OpenContainer<bool>(
//openColor: Colors.transparent,
closedColor: Colors.black87.withOpacity(0.2),
transitionType: ContainerTransitionType.fadeThrough,
openBuilder: (BuildContext _, VoidCallback openContainer) {
c.notificacoesResults[index].visualizado = true;
c.getNotificacaoDetail(c.notificacoesResults[index].iD);
//return _DetailsPage();
return NotificacaoDetail();
},
onClosed: (bool isMarkedAsDone) {
c.notificacaoLidaBloc(c.notificacoesResults[index].iD);
if (isMarkedAsDone ?? false)
Get.rawSnackbar(message: 'Marked as done!');
},
tappable: false,
closedShape: const RoundedRectangleBorder(),
closedElevation: 0.0,
closedBuilder: (BuildContext _, VoidCallback openContainer) {
return this._buildListTileTile(index: index,onTap: openContainer);
},
);
}
Widget _buildListTileTile({Function onTap,@required int index}){
return ListTile(
leading: CircleAvatar(
backgroundImage: GetUtils.isNullOrBlank(c.notificacoesResults[index].imageUrl) ? AssetImage(
'assets/images/logo.png',
) : NetworkImage(c.notificacoesResults[index].imageUrl),
// child: Image.asset(
// 'assets/images/logo.png',
// width: 40,
// ),
),
onTap: onTap,
trailing: c.notificacoesResults[index].visualizado ? Text('') : Text('',style: TextStyle(color: Colors.blue),),
title: Text(c.notificacoesResults[index].titulo),
subtitle: Text(c.getDateFormatada(c.notificacoesResults[index].dataNotificacao)),
);
}
}
@@ -0,0 +1,102 @@
//import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart' show DateFormat;
import 'api/notificacoes_api.dart';
import 'api/notificacoes_classes.dart';
class NotificacoesController extends GetxController with SingleGetTickerProviderMixin{
var notificacoesResults = List<NotificacaoResults>().obs;
bool loadMore = true;
NotificacoesApi _api = new NotificacoesApi();
var notificacaoDetail = NotificacaoResponse().obs;
int page = 1;
var errorCode = 0.obs;
var errorMessage = '';
var loading = true.obs;
var loadingDetail = true.obs;
var like = ''.obs;
final f = DateFormat('dd/MM/yyyy HH:mm:ss');
//final GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>();
// AnimationController _controller;
// Animation<Offset> animation;
@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.notificacoesResults = new RxList<NotificacaoResults>();
this.getNotificacoesBloc();
}
getNotificacoesBloc()async{
var response = await this._api.getNotificacoes(page);
this.loadMore = response.results.length < 1 ? false : true;
if(response.errorCode != 0){
this.errorCode.value = response.errorCode;
this.errorMessage = response.errorMessage;
}
else{
//if(this.page > 1)this.listKey.currentState.insertItem(2,duration: const Duration(milliseconds: 1500));
page++;
this.notificacoesResults.addAll(response.results);
}
if(this.loading.value)this.loading.value = false;
}
getNotificacaoDetail(int id) async {
this.loadingDetail.value = true;
this.notificacaoDetail.value.result = new NotificacaoResults();
var response = await this._api.getNotificacao(id);
this.notificacaoDetail.value = response;
this.like.value = response.result.like;
this.loadingDetail.value = false;
}
Future<void> refresh() async{
this.loading.value = true;
this.page = 1;
this.notificacoesResults = new RxList<NotificacaoResults>();
this.getNotificacoesBloc();
}
String get getLike => this.like.value;
Future<void> notificacaoLikeBloc(NotificacaoLikeRequest item) async {
var response = await this._api.notificacaoLike(item);
if(response != null && response.errorCode == 0)
{
this.notificacaoDetail.value.result.like = item.like;
this.like.value = item.like;
}
}
String getDateFormatada(String dt){
String r = '';
try {
r = this.f.format(DateTime.parse(dt));
} catch (e) {
}
return r;
}
Future<void> notificacaoLidaBloc(int notificacaoID) async {
return;
}
}