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
+11 -9
View File
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'package:get/get_utils/src/get_utils/get_utils.dart';
import 'package:http/http.dart' as http;
import '../../default_response_api.dart';
@@ -26,9 +27,10 @@ class NotificacoesApi{
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var response = await http.get(url, headers: heads);
var response = await http.get(Uri.parse(url), headers: heads);
if (response != null) {
//if (response != null) {
if (!GetUtils.isNullOrBlank(response.body)!) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
retorno = NotificacoesResponse.fromJson(data);
@@ -47,7 +49,7 @@ class NotificacoesApi{
return retorno;
}
Future<NotificacaoResponse> getNotificacao(int id) async{
Future<NotificacaoResponse> getNotificacao(int? id) async{
var retorno = new NotificacaoResponse(
errorCode: 0,
errorMessage: ""
@@ -63,9 +65,9 @@ class NotificacoesApi{
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
var response = await http.get(url, headers: heads);
var response = await http.get(Uri.parse(url), headers: heads);
if (response != null) {
if (!GetUtils.isNullOrBlank(response.body)!) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
retorno = NotificacaoResponse.fromJson(data);
@@ -100,9 +102,9 @@ class NotificacoesApi{
var body = json.encode(post);
var response = await http.post(url, headers: heads, body: body);
var response = await http.post(Uri.parse(url), headers: heads, body: body);
if (response != null) {
if (!GetUtils.isNullOrBlank(response.body)!) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
objRetorno = DefaultResponseApi.fromJson(data);
@@ -135,10 +137,10 @@ class NotificacoesApi{
var body = json.encode(post);
var response = await http.post(url, headers: heads, body: body);
var response = await http.post(Uri.parse(url), headers: heads, body: body);
if (response != null) {
if (!GetUtils.isNullOrBlank(response.body)!) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
objRetorno = DefaultResponseApi.fromJson(data);
+24 -24
View File
@@ -1,6 +1,6 @@
class NotificacaoLikeRequest {
int iD;
String like;
int? iD;
String? like;
NotificacaoLikeRequest({this.iD, this.like});
@@ -18,8 +18,8 @@ class NotificacaoLikeRequest {
}
class NotificacaoLidaRequest {
String latitude;
String longitude;
String? latitude;
String? longitude;
NotificacaoLidaRequest({this.latitude, this.longitude});
@@ -38,9 +38,9 @@ class NotificacaoLidaRequest {
class NotificacaoResponse {
NotificacaoResults result;
int errorCode;
String errorMessage;
NotificacaoResults? result;
int? errorCode;
String? errorMessage;
NotificacaoResponse({this.result, this.errorCode, this.errorMessage});
@@ -54,7 +54,7 @@ class NotificacaoResponse {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.result != null) {
data['Result'] = this.result.toJson();
data['Result'] = this.result!.toJson();
}
data['ErrorCode'] = this.errorCode;
data['ErrorMessage'] = this.errorMessage;
@@ -63,18 +63,18 @@ class NotificacaoResponse {
}
class NotificacoesResponse {
List<NotificacaoResults> results;
int errorCode;
String errorMessage;
bool loadMore;
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>();
results = <NotificacaoResults>[];
json['Results'].forEach((v) {
results.add(new NotificacaoResults.fromJson(v));
results!.add(new NotificacaoResults.fromJson(v));
});
}
errorCode = json['ErrorCode'];
@@ -84,7 +84,7 @@ class NotificacoesResponse {
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['Results'] = this.results!.map((v) => v.toJson()).toList();
}
data['ErrorCode'] = this.errorCode;
data['ErrorMessage'] = this.errorMessage;
@@ -93,15 +93,15 @@ class NotificacoesResponse {
}
class NotificacaoResults {
int iD;
String titulo;
String texto;
String conteudo;
String dataNotificacao;
String tipoConteudo;
bool visualizado;
String imageUrl;
String like;
int? iD;
String? titulo;
String? texto;
String? conteudo;
String? dataNotificacao;
String? tipoConteudo;
bool? visualizado;
String? imageUrl;
String? like;
NotificacaoResults(
{this.iD,
+10 -7
View File
@@ -15,17 +15,17 @@ class NotificacaoDetail extends StatelessWidget {
//
//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(
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,
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 ?? '',
c.notificacaoDetail.value.result!.imageUrl ?? '',
fit: BoxFit.contain,
),
),
@@ -37,14 +37,17 @@ class NotificacaoDetail extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
c.notificacaoDetail.value.result.titulo,
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);
data: c.notificacaoDetail.value.result!.conteudo,
// onLinkTap: (url){
// launch(url);
// },
onLinkTap: (url,ctx,mp,element){
launch(url!);
},
// style: Theme.of(context).textTheme.bodyText2.copyWith(
// color: Colors.black54,
+14 -13
View File
@@ -71,7 +71,7 @@ class NotificacoesScreen extends StatelessWidget {
// child: this._buildListTile(index)
// );
} else if (index > 1) {
if(c.loadMore == null || c.loadMore){
if(c.loadMore){
c.getNotificacoesBloc();
return Container(
height: 40,
@@ -113,8 +113,9 @@ class NotificacoesScreen extends StatelessWidget {
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'),)
],
),
);
@@ -123,12 +124,12 @@ class NotificacoesScreen extends StatelessWidget {
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));
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),
closedColor: Get.theme.primaryColor.withOpacity(0.2),
transitionType: ContainerTransitionType.fadeThrough,
openBuilder: (BuildContext _, VoidCallback openContainer) {
c.notificacoesResults[index].visualizado = true;
@@ -136,7 +137,7 @@ class NotificacoesScreen extends StatelessWidget {
//return _DetailsPage();
return NotificacaoDetail();
},
onClosed: (bool isMarkedAsDone) {
onClosed: (bool? isMarkedAsDone) {
c.notificacaoLidaBloc(c.notificacoesResults[index].iD);
if (isMarkedAsDone ?? false)
Get.rawSnackbar(message: 'Marked as done!');
@@ -150,21 +151,21 @@ class NotificacoesScreen extends StatelessWidget {
);
}
Widget _buildListTileTile({Function onTap,@required int index}){
Widget _buildListTileTile({Function? onTap,required int index}){
return ListTile(
leading: CircleAvatar(
backgroundImage: GetUtils.isNullOrBlank(c.notificacoesResults[index].imageUrl) ? AssetImage(
backgroundImage: (GetUtils.isNullOrBlank(c.notificacoesResults[index].imageUrl)! ? AssetImage(
'assets/images/logo.png',
) : NetworkImage(c.notificacoesResults[index].imageUrl),
) : NetworkImage(c.notificacoesResults[index].imageUrl!)) as ImageProvider<Object>?,
// 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)),
onTap: onTap as void Function()?,
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!)),
);
}
}
+12 -11
View File
@@ -5,13 +5,13 @@ import 'api/notificacoes_api.dart';
import 'api/notificacoes_classes.dart';
class NotificacoesController extends GetxController with SingleGetTickerProviderMixin{
var notificacoesResults = List<NotificacaoResults>().obs;
var notificacoesResults = <NotificacaoResults>[].obs;
bool loadMore = true;
NotificacoesApi _api = new NotificacoesApi();
var notificacaoDetail = NotificacaoResponse().obs;
int page = 1;
var errorCode = 0.obs;
var errorMessage = '';
String? errorMessage = '';
var loading = true.obs;
var loadingDetail = true.obs;
var like = ''.obs;
@@ -45,27 +45,27 @@ class NotificacoesController extends GetxController with SingleGetTickerProvider
getNotificacoesBloc()async{
var response = await this._api.getNotificacoes(page);
this.loadMore = response.results.length < 1 ? false : true;
this.loadMore = response.results!.length < 1 ? false : true;
if(response.errorCode != 0){
this.errorCode.value = response.errorCode;
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);
this.notificacoesResults.addAll(response.results!);
}
if(this.loading.value)this.loading.value = false;
}
getNotificacaoDetail(int id) async {
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.like.value = response.result!.like!;
this.loadingDetail.value = false;
}
@@ -80,10 +80,11 @@ class NotificacoesController extends GetxController with SingleGetTickerProvider
Future<void> notificacaoLikeBloc(NotificacaoLikeRequest item) async {
var response = await this._api.notificacaoLike(item);
if(response != null && response.errorCode == 0)
//if(response != null && response.errorCode == 0)
if(response.errorCode != null && response.errorCode == 0)
{
this.notificacaoDetail.value.result.like = item.like;
this.like.value = item.like;
this.notificacaoDetail.value.result!.like = item.like;
this.like.value = item.like!;
}
}
@@ -96,7 +97,7 @@ class NotificacoesController extends GetxController with SingleGetTickerProvider
return r;
}
Future<void> notificacaoLidaBloc(int notificacaoID) async {
Future<void> notificacaoLidaBloc(int? notificacaoID) async {
return;
}
}