Protótipo Vilacorp

This commit is contained in:
2021-09-15 09:18:36 -03:00
parent c995325ba7
commit 001ee87e87
58 changed files with 502 additions and 437 deletions
+50 -58
View File
@@ -6,52 +6,49 @@ import 'dart:io';
import 'default_response_api.dart';
class FuncoesGerais{
class FuncoesGerais {
//static const String urlLexLiteApi = "https://apis.lexstation.com/api/v1/";
static const String tokenPadrao = "6JN4NNEP6IDEK7I2BCXTA7D1DPJR78";
static const String tokenPadrao = "GA9P876KYL2XNHHKMU0VSHEEYEL37D";
static const String urlBaseNewCore = "https://newcore.services/newcore/";
static const int appMobileCodigo = 18;
static const String nomeApp = "Decpisos";
static const String nomeApp = "Vilacorp";
static const int versaoAtual = 100;
static const int usuCodPadrao = 36718;
static const String youtubeApiKey = "AIzaSyAmqjP0MxgASbt98Px1_hqaIvcsqeHO15k";//"AIzaSyA8jo3qsr-JJRm40iSHfkrzaMZXdMjo9v4";
static const String channelId = "UCJ_EUoswNTvRGotJ-ROxaKw";
static const String homeURL = "https://www.decpisos.com.br/produtos-listar";
static const String dominioPermitido = "https://www.decpisos.com.br";
static const String urlPDF = "http://app-cards.com/files/card-decpisos.pdf";
static const int usuCodPadrao = 70435;
static const String youtubeApiKey =
"AIzaSyAmqjP0MxgASbt98Px1_hqaIvcsqeHO15k"; //"AIzaSyA8jo3qsr-JJRm40iSHfkrzaMZXdMjo9v4";
static const String channelId = "UCJ_EUoswNTvRGotJ-ROxaKw";
static const String homeURL = "https://vilacorp.com.br/";
static const String dominioPermitido = "https://vilacorp.com.br/";
static const String urlPDF = "http://app-cards.com/files/vilacorp.pdf";
static Future<bool> checkInternetConnection() async{
static Future<bool> checkInternetConnection() async {
bool retorno = true;
try {
final result = await InternetAddress.lookup('google.com').timeout(Duration(seconds: 5));
final result = await InternetAddress.lookup('google.com')
.timeout(Duration(seconds: 5));
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
retorno = true;
}
else{
} else {
retorno = false;
}
} on SocketException catch (_) {
retorno = false;
}
catch(err){
} catch (err) {
retorno = false;
}
}
return retorno;
}
static Future<String> getUsuToken()async{
static Future<String> getUsuToken() async {
return Future<String>.value(tokenPadrao);
}
static Future<void> registraDevice(String? token) async{
if(await FuncoesGerais.checkInternetConnection()){
if(token != null && token.isNotEmpty){
String url = FuncoesGerais.urlBaseNewCore+ "api/v1/user/${FuncoesGerais.tokenPadrao}/registra_device";
static Future<void> registraDevice(String? token) async {
if (await FuncoesGerais.checkInternetConnection()) {
if (token != null && token.isNotEmpty) {
String url = FuncoesGerais.urlBaseNewCore +
"api/v1/user/${FuncoesGerais.tokenPadrao}/registra_device";
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
heads["auth-key"] = token;
@@ -66,8 +63,8 @@ class FuncoesGerais{
platformCoddigo = 1;
var info = await deviceInfo.iosInfo;
model = info.utsname.machine;
}
}
var objPost = new RegistraDeviceRequest(
aPPMOBILECODIGO: appMobileCodigo,
dEVICETOKEN: token,
@@ -79,7 +76,7 @@ class FuncoesGerais{
try {
var body = json.encode(objPost);
//var response = await http.post(url, body: body,headers: heads);
await http.post(Uri.parse(url), body: body,headers: heads);
await http.post(Uri.parse(url), body: body, headers: heads);
//var r = await http.post(url, body: body,headers: heads);
//print(r);
// if (response != null) {
@@ -88,32 +85,30 @@ class FuncoesGerais{
// retorno = LoginResponse.fromJson(data);
// }
// }
} catch (e) {
}
}
} catch (e) {}
}
}
// else{
// print('Nada');
// }
// }
}
static Future<VersaoMinimaResponse> checkVersaoMinimaOk() async{
static Future<VersaoMinimaResponse> checkVersaoMinimaOk() async {
VersaoMinimaResponse objRetorno = VersaoMinimaResponse(
errorCode: 0,
errorMessage: '',
linkLoja: '',
nome: '',
versaoMinima: 0,
vOk: true
);
if(await FuncoesGerais.checkInternetConnection()){
String url = FuncoesGerais.urlBaseNewCore + "api/v1/appmobile/${FuncoesGerais.tokenPadrao}/versaominima/$appMobileCodigo";
errorCode: 0,
errorMessage: '',
linkLoja: '',
nome: '',
versaoMinima: 0,
vOk: true);
if (await FuncoesGerais.checkInternetConnection()) {
String url = FuncoesGerais.urlBaseNewCore +
"api/v1/appmobile/${FuncoesGerais.tokenPadrao}/versaominima/$appMobileCodigo";
Map<String, String> heads = Map();
heads["Content-type"] = "application/json; charset=utf-8";
try {
http.Response response = await http.get(Uri.parse(url),headers: heads);
http.Response response = await http.get(Uri.parse(url), headers: heads);
if (!GetUtils.isNullOrBlank(response.body)!) {
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
@@ -122,30 +117,27 @@ class FuncoesGerais{
// var v = packageInfo.version.split('.');
// int versaoAtual = 0;
//if(v.length > 0)versaoAtual = v[0] != null && v[0].isNotEmpty ? int.parse(v[0]) : 0;
if(objRetorno.versaoMinima! > FuncoesGerais.versaoAtual){
if (objRetorno.versaoMinima! > FuncoesGerais.versaoAtual) {
objRetorno.vOk = false;
}
}
else{
} else {
objRetorno.errorCode = 4;
objRetorno.errorMessage = 'Falha na comunição com a API error:${response.statusCode}.';
objRetorno.errorMessage =
'Falha na comunição com a API error:${response.statusCode}.';
}
}
else{
} else {
objRetorno.errorCode = 3;
objRetorno.errorMessage = 'Falha na comunição com o server.';
objRetorno.errorMessage = 'Falha na comunição com o server.';
}
} catch (e) {
objRetorno.errorCode = 2;
objRetorno.errorMessage = 'Falha na comunição com o server.';
}
}
else{
}
} else {
objRetorno.errorCode = 1;
objRetorno.errorMessage = 'Sem Conexão com a internet.';
}
return objRetorno;
}
}
return objRetorno;
}
}
+57 -52
View File
@@ -1,5 +1,5 @@
import 'package:decpisos/charts/radial_gauge.dart';
import 'package:decpisos/funcoes_gerais.dart';
import 'package:vilacorp/charts/radial_gauge.dart';
import 'package:vilacorp/funcoes_gerais.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:line_icons/line_icons.dart';
@@ -7,13 +7,13 @@ import 'package:syncfusion_flutter_gauges/gauges.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> with AutomaticKeepAliveClientMixin<HomeScreen> {
class _HomeScreenState extends State<HomeScreen>
with AutomaticKeepAliveClientMixin<HomeScreen> {
bool error = false;
String msg = '';
@override
@@ -25,66 +25,71 @@ class _HomeScreenState extends State<HomeScreen> with AutomaticKeepAliveClientMi
centerTitle: false,
actions: [
IconButton(
onPressed: (){
if(Get.theme.brightness == Brightness.dark){
Get.changeThemeMode(ThemeMode.light);
}
else{
Get.changeThemeMode(ThemeMode.dark);
}
},
tooltip: 'Alternar modo dark/light',
icon: Icon(LineIcons.palette)
),
IconButton(onPressed: (){
Get.bottomSheet(BottomSheet(onClosing: ()=>null, builder: (_){
return Padding(
padding: const EdgeInsets.all(8.0),
child: RadialEaseExample(),
);
}));
//Get.to(() => Scaffold(appBar: AppBar(),body: RadialEaseExample()));
}, icon: Icon(Icons.monetization_on_outlined))
onPressed: () {
if (Get.theme.brightness == Brightness.dark) {
Get.changeThemeMode(ThemeMode.light);
} else {
Get.changeThemeMode(ThemeMode.dark);
}
},
tooltip: 'Alternar modo dark/light',
icon: Icon(LineIcons.palette)),
// IconButton(
// onPressed: () {
// Get.bottomSheet(BottomSheet(
// onClosing: () => null,
// builder: (_) {
// return Padding(
// padding: const EdgeInsets.all(8.0),
// child: RadialEaseExample(),
// );
// }));
// //Get.to(() => Scaffold(appBar: AppBar(),body: RadialEaseExample()));
// },
// icon: Icon(Icons.monetization_on_outlined))
],
),
body: SafeArea(
child: this.error ? this._buildError() : WebView(
initialUrl: FuncoesGerais.homeURL,
javascriptMode: JavascriptMode.unrestricted,
onWebResourceError: (err){
this.error = true;
this.msg = err.description;
setState(() {
});
},
allowsInlineMediaPlayback: true,
navigationDelegate: (navigation){
print(navigation.url);
if (navigation.url.startsWith(FuncoesGerais.dominioPermitido)) {
return NavigationDecision.navigate;
}
//print('allowing navigation to $request');
launch(navigation.url);
return NavigationDecision.prevent;
},
),
child: this.error
? this._buildError()
: WebView(
initialUrl: FuncoesGerais.homeURL,
javascriptMode: JavascriptMode.unrestricted,
onWebResourceError: (err) {
this.error = true;
this.msg = err.description;
setState(() {});
},
allowsInlineMediaPlayback: true,
navigationDelegate: (navigation) {
print(navigation.url);
if (navigation.url
.startsWith(FuncoesGerais.dominioPermitido)) {
return NavigationDecision.navigate;
}
//print('allowing navigation to $request');
launch(navigation.url);
return NavigationDecision.prevent;
},
),
),
);
}
Widget _buildError(){
Widget _buildError() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(msg),
ElevatedButton(onPressed: (){
this.error = false;
this.msg = '';
setState(() {
});
}, child: Text('Atualizar'))
ElevatedButton(
onPressed: () {
this.error = false;
this.msg = '';
setState(() {});
},
child: Text('Atualizar'))
// RaisedButton(onPressed: (){
// this.error = false;
// this.msg = '';
@@ -98,4 +103,4 @@ class _HomeScreenState extends State<HomeScreen> with AutomaticKeepAliveClientMi
@override
bool get wantKeepAlive => true;
}
}
+5 -5
View File
@@ -1,7 +1,7 @@
//import 'package:decpisos/home/home.dart';
import 'package:decpisos/index/index_controller.dart';
//import 'package:decpisos/notificacoes/notificacoes.dart';
//import 'package:decpisos/videos/youtube_videos.dart';
//import 'package:vilacorp/home/home.dart';
import 'package:vilacorp/index/index_controller.dart';
//import 'package:vilacorp/notificacoes/notificacoes.dart';
//import 'package:vilacorp/videos/youtube_videos.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -40,7 +40,7 @@ class _IndexScreenState extends State<IndexScreen> {
// NotificacoesScreen()
// ]
children: c.childrenTabs.map((element) => element).toList(),
)),
)),
bottomNavigationBar: Obx(() => ConvexAppBar(
// items: [
// TabItem(icon: Icons.video_collection, title: 'Vídeos'),
+7 -8
View File
@@ -1,9 +1,9 @@
import 'package:decpisos/home/home.dart';
//import 'package:decpisos/instagram_embed/instagram_embed.dart';
import 'package:decpisos/notificacoes/notificacoes.dart';
//import 'package:decpisos/videos/youtube_videos.dart';
import 'package:vilacorp/home/home.dart';
//import 'package:vilacorp/instagram_embed/instagram_embed.dart';
import 'package:vilacorp/notificacoes/notificacoes.dart';
//import 'package:vilacorp/videos/youtube_videos.dart';
import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:decpisos/pdfviewer/pdfviewer.dart';
import 'package:vilacorp/pdfviewer/pdfviewer.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:line_icons/line_icons.dart';
@@ -36,9 +36,8 @@ class IndexController extends GetxController with SingleGetTickerProviderMixin {
this.childrenTabs.add(Tab(child: NotificacoesScreen()));
//this.tabs.add(TabItem(icon: Icons.video_collection, title: 'Vídeos'));
//this.tabs.add(TabItem(icon: LineIcons.instagram, title: 'Instagram'));
this
.tabs
.add(TabItem(icon: LineIcons.identificationCard, title: 'DecCard'));
this.tabs.add(
TabItem(icon: LineIcons.identificationCard, title: 'Vilacorp card'));
this.tabs.add(TabItem(icon: Icons.home, title: 'Home'));
this.tabs.add(TabItem(icon: Icons.notifications, title: 'Notificações'));
this.tabController = TabController(vsync: this, length: this.tabs.length);
+32 -29
View File
@@ -1,4 +1,4 @@
//import 'package:decpisos/funcoes_gerais.dart';
//import 'package:vilacorp/funcoes_gerais.dart';
import 'package:flutter/material.dart';
//import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter/webview_flutter.dart';
@@ -8,48 +8,51 @@ class InstagramScreen extends StatefulWidget {
_InstagramScreenState createState() => _InstagramScreenState();
}
class _InstagramScreenState extends State<InstagramScreen> with AutomaticKeepAliveClientMixin<InstagramScreen> {
class _InstagramScreenState extends State<InstagramScreen>
with AutomaticKeepAliveClientMixin<InstagramScreen> {
bool error = false;
String msg = '';
@override
Widget build(BuildContext context) {
super.build(context);
return SafeArea(
child: this.error ? this._buildError() : WebView(
initialUrl: 'https://blog.hightechx.com/teste-feed-instagram/',
javascriptMode: JavascriptMode.unrestricted,
onWebResourceError: (err){
this.error = true;
this.msg = err.description;
setState(() {
});
},
// navigationDelegate: (navigation){
// print(navigation.url);
// if (navigation.url.startsWith(FuncoesGerais.dominioPermitido)) {
// return NavigationDecision.navigate;
// }
// //print('allowing navigation to $request');
// launch(navigation.url);
// return NavigationDecision.prevent;
// },
),
child: this.error
? this._buildError()
: WebView(
initialUrl: 'https://blog.hightechx.com/teste-feed-instagram/',
javascriptMode: JavascriptMode.unrestricted,
onWebResourceError: (err) {
this.error = true;
this.msg = err.description;
setState(() {});
},
// navigationDelegate: (navigation){
// print(navigation.url);
// if (navigation.url.startsWith(FuncoesGerais.dominioPermitido)) {
// return NavigationDecision.navigate;
// }
// //print('allowing navigation to $request');
// launch(navigation.url);
// return NavigationDecision.prevent;
// },
),
);
}
Widget _buildError(){
Widget _buildError() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(msg),
ElevatedButton(onPressed: (){
this.error = false;
this.msg = '';
setState(() {
});
}, child: Text('Atualizar'))
ElevatedButton(
onPressed: () {
this.error = false;
this.msg = '';
setState(() {});
},
child: Text('Atualizar'))
// RaisedButton(onPressed: (){
// this.error = false;
// this.msg = '';
@@ -63,4 +66,4 @@ class _InstagramScreenState extends State<InstagramScreen> with AutomaticKeepAli
@override
bool get wantKeepAlive => true;
}
}
+20 -22
View File
@@ -1,4 +1,4 @@
import 'package:decpisos/funcoes_gerais.dart';
import 'package:vilacorp/funcoes_gerais.dart';
import 'package:firebase_core/firebase_core.dart';
//import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
@@ -17,25 +17,23 @@ Future<void> main() async {
// });
runApp(GetMaterialApp(
title: FuncoesGerais.nomeApp,
localizationsDelegates: [
// ... app-specific localization delegate[s] here
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
supportedLocales: [
const Locale('pt'),
],
theme: ThemeData.light().copyWith(primaryColor: Color(0xFF05578e)),
darkTheme: ThemeData.dark().copyWith(primaryColor: Colors.black87),
// theme: ThemeData(
// //brightness: Brightness.dark,
// visualDensity: VisualDensity.adaptivePlatformDensity,
// primarySwatch: Colors.blueGrey
// ),
themeMode: ThemeMode.dark,
home: SplashScreen()
));
title: FuncoesGerais.nomeApp,
localizationsDelegates: [
// ... app-specific localization delegate[s] here
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
supportedLocales: [
const Locale('pt'),
],
theme: ThemeData.light().copyWith(primaryColor: Color(0xFF05578e)),
darkTheme: ThemeData.dark().copyWith(primaryColor: Colors.black87),
// theme: ThemeData(
// //brightness: Brightness.dark,
// visualDensity: VisualDensity.adaptivePlatformDensity,
// primarySwatch: Colors.blueGrey
// ),
themeMode: ThemeMode.dark,
home: SplashScreen()));
}
+15 -9
View File
@@ -1,5 +1,5 @@
//import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
import 'package:decpisos/pdfviewer/pdfviewer_controller.dart';
import 'package:vilacorp/pdfviewer/pdfviewer_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:get/get.dart';
@@ -10,13 +10,17 @@ class PDFViewerScreen extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('DecCard'),
title: Text('Vilacorp card'),
centerTitle: false,
leading: Container(),
leadingWidth: 0,
actions: [
Obx(() => c.loadPDF.value ? Center(child: CircularProgressIndicator()) : IconButton(icon: Icon(Icons.share), onPressed: c.sharePDF)),
Obx(() => c.visibleRefresh.value ? IconButton(icon: Icon(Icons.refresh), onPressed: c.refreshPDF) : Container())
Obx(() => c.loadPDF.value
? Center(child: CircularProgressIndicator())
: IconButton(icon: Icon(Icons.share), onPressed: c.sharePDF)),
Obx(() => c.visibleRefresh.value
? IconButton(icon: Icon(Icons.refresh), onPressed: c.refreshPDF)
: Container())
],
),
// body: Obx(() => c.loading.value
@@ -31,11 +35,13 @@ class PDFViewerScreen extends StatelessWidget {
? Center(
child: CircularProgressIndicator(),
)
: c.error.value ? c.buildError() : PDFView(
filePath: c.filePDF!.path,
//nightMode: true,
fitPolicy: FitPolicy.BOTH,
)),
: c.error.value
? c.buildError()
: PDFView(
filePath: c.filePDF!.path,
//nightMode: true,
fitPolicy: FitPolicy.BOTH,
)),
);
}
}
+23 -21
View File
@@ -1,14 +1,14 @@
import 'dart:io' as io;
//import 'package:advance_pdf_viewer/advance_pdf_viewer.dart';
import 'package:decpisos/funcoes_gerais.dart';
import 'package:vilacorp/funcoes_gerais.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share/share.dart';
class PDFViewerScreenController extends GetxController{
class PDFViewerScreenController extends GetxController {
var loading = true.obs;
var loadPDF = false.obs;
var visibleRefresh = false.obs;
@@ -29,7 +29,7 @@ class PDFViewerScreenController extends GetxController{
// this.doc = await PDFDocument.fromFile(file);
// //this.doc = await PDFDocument.fromFile(file);
// //this.visibleRefresh.value = true;
// }
// }
// else{
// if(await FuncoesGerais.checkInternetConnection() == false){
// this.error.value = true;
@@ -37,10 +37,10 @@ class PDFViewerScreenController extends GetxController{
// else{
// this.doc = await PDFDocument.fromURL(FuncoesGerais.urlPDF);
// }
// }
if(file == null || await file.exists() == false){
// }
if (file == null || await file.exists() == false) {
this.error.value = true;
}
@@ -63,13 +63,13 @@ class PDFViewerScreenController extends GetxController{
this.loadPDF.value = true;
var file = await this._createFileOfPdfUrl();
try {
Share.shareFiles([file!.path], text: 'DecCard').then((value) => this.loadPDF.value = false);
Share.shareFiles([file!.path], text: 'Vilacorp card')
.then((value) => this.loadPDF.value = false);
} catch (e) {
this.loadPDF.value = false;
Get.rawSnackbar(message: 'Não foi possível compartilhar o PDF');
}
}
}
Future<io.File?> _createFileOfPdfUrl() async {
final url = FuncoesGerais.urlPDF;
@@ -78,24 +78,24 @@ class PDFViewerScreenController extends GetxController{
final filename = url.substring(url.lastIndexOf("/") + 1);
String dir = (await getApplicationDocumentsDirectory()).path;
file = io.File('$dir/$filename');
if(!await file.exists()){
if(await FuncoesGerais.checkInternetConnection()){
if (!await file.exists()) {
if (await FuncoesGerais.checkInternetConnection()) {
var request = await io.HttpClient().getUrl(Uri.parse(url));
var response = await request.close();
var bytes = await consolidateHttpClientResponseBytes(response);
await file.writeAsBytes(bytes);
}
else{
} else {
file = null;
}
}
}
this.filePDF = file;
if(this.filePDF != null) this.visibleRefresh.value = await this.filePDF!.exists();
if (this.filePDF != null)
this.visibleRefresh.value = await this.filePDF!.exists();
return file;
}
}
Widget buildError(){
Widget buildError() {
return Container(
width: double.maxFinite,
child: Column(
@@ -103,11 +103,13 @@ class PDFViewerScreenController extends GetxController{
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Não foi possível carregar o PDF'),
SizedBox(height: 10.0,),
ElevatedButton(onPressed: this.refreshPDF,child: Text('Atualizar'))
SizedBox(
height: 10.0,
),
ElevatedButton(onPressed: this.refreshPDF, child: Text('Atualizar'))
//RaisedButton(onPressed: this.refreshPDF,child: Text('Atualizar'),)
],
),
);
}
}
}
+21 -7
View File
@@ -1,10 +1,11 @@
import 'package:decpisos/funcoes_gerais.dart';
import 'package:vilacorp/funcoes_gerais.dart';
import 'package:flutter/material.dart';
import 'package:animated_splash_screen/animated_splash_screen.dart';
import 'package:get/get.dart';
import 'package:page_transition/page_transition.dart';
import 'splash_controller.dart';
class SplashScreen extends StatelessWidget {
final SplashController c = Get.put(SplashController());
@override
@@ -19,11 +20,24 @@ class SplashScreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Container(width: 120.0,height: 120.0,child: Image.asset('assets/images/logo.png',fit: BoxFit.contain,))
borderRadius: BorderRadius.circular(8.0),
child: Container(
width: 120.0,
height: 120.0,
child: Image.asset(
'assets/images/logo.png',
fit: BoxFit.contain,
))),
SizedBox(
height: 10.0,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
FuncoesGerais.nomeApp,
style: TextStyle(color: Colors.white, fontSize: 22.0),
),
),
SizedBox(height: 10.0,),
Text(FuncoesGerais.nomeApp,style: TextStyle(color: Colors.green.shade600,fontSize: 22.0),),
LinearProgressIndicator()
],
),
@@ -33,7 +47,7 @@ class SplashScreen extends StatelessWidget {
splashTransition: SplashTransition.slideTransition,
pageTransitionType: PageTransitionType.fade,
backgroundColor: Colors.blueGrey.shade800,
screenFunction: ()async{
screenFunction: () async {
await c.firebaseCloudMessagingListeners();
//await c.verTutorial();
var screen = await c.verUsuLogado();
@@ -42,4 +56,4 @@ class SplashScreen extends StatelessWidget {
//backgroundColor: Colors.blue
);
}
}
}
+23 -27
View File
@@ -1,8 +1,8 @@
import 'dart:io';
import 'package:decpisos/atualizarapp/atualizarapp.dart';
import 'package:decpisos/index/index.dart';
import 'package:decpisos/notificacoes/notificacoes.dart';
import 'package:vilacorp/atualizarapp/atualizarapp.dart';
import 'package:vilacorp/index/index.dart';
import 'package:vilacorp/notificacoes/notificacoes.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -12,11 +12,10 @@ import 'package:shared_preferences/shared_preferences.dart';
import '../funcoes_gerais.dart';
class SplashController extends GetxController {
//bool _tutorialOk = false;
//FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
//FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
@override
void onInit() {
super.onInit();
@@ -29,26 +28,23 @@ class SplashController extends GetxController {
// Future<void> verTutorial()async{
// SharedPreferences prefs = await SharedPreferences.getInstance();
// this._tutorialOk = prefs.getBool('tutorial') ?? false;
// this._tutorialOk = prefs.getBool('tutorial') ?? false;
// }
Future<Widget> verUsuLogado()async{
Future<Widget> verUsuLogado() async {
var resp = await FuncoesGerais.checkVersaoMinimaOk();
if(resp.vOk!){
if (resp.vOk!) {
SharedPreferences prefs = await SharedPreferences.getInstance();
var token = prefs.getString('token_notif');
await FuncoesGerais.registraDevice(token);
return IndexScreen();
}
else{
} else {
return AtualizarScreen(linkLoja: resp.linkLoja);
}
}
}
}
Future<void> firebaseCloudMessagingListeners() async{
Future<void> firebaseCloudMessagingListeners() async {
try {
//if (_firebaseMessaging == null) return;
if (Platform.isIOS) iOSPermission();
@@ -58,7 +54,7 @@ class SplashController extends GetxController {
// SharedPreferences prefs = await SharedPreferences.getInstance();
// await prefs.setString('token_notif', token);
// });
FirebaseMessaging.instance.getToken().then((token) async{
FirebaseMessaging.instance.getToken().then((token) async {
print(token);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('token_notif', token!);
@@ -69,26 +65,28 @@ class SplashController extends GetxController {
// //onBackgroundMessage: this._onNotification,
// onResume: this._onNotification
// );
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Push onMessage');
Get.snackbar(message.notification!.title ?? 'Notificação', message.notification!.body ?? 'Nova notificação',
mainButton: TextButton(onPressed: () => this._onNotification(message), child: Text('Ver')),
backgroundColor: Colors.black.withOpacity(0.7),
colorText: Colors.white
);
Get.snackbar(message.notification!.title ?? 'Notificação',
message.notification!.body ?? 'Nova notificação',
mainButton: TextButton(
onPressed: () => this._onNotification(message),
child: Text('Ver')),
backgroundColor: Colors.black.withOpacity(0.7),
colorText: Colors.white);
//this._onNotification(message);
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published!');
print(message);
//Get.snackbar(message.notification!.title ?? 'Notificação', message.notification!.body ?? 'Nova notificação',mainButton: TextButton(onPressed: () => this._onNotification(message), child: Text('Ver')));
});
});
} on PlatformException catch (e) {
print(e.message);
}
}
void _onNotification(RemoteMessage message){
void _onNotification(RemoteMessage message) {
Get.to(() => NotificacoesScreen());
//print(message);
//print(message['aps']['alert']['title']);
@@ -103,7 +101,5 @@ class SplashController extends GetxController {
// .listen((IosNotificationSettings settings) {
// print("Settings registered: $settings");
// });
}
}
}
+42 -32
View File
@@ -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;
}
}
}
+79 -68
View File
@@ -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
],
),
);
}
}
}
}