Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Comunicacao HSL
Comunicação HSL Frontend
Commits
0a60f20c
Commit
0a60f20c
authored
3 years ago
by
Lucas Abruzzi da Rosa
Browse files
Options
Download
Email Patches
Plain Diff
Setup do firebase para web (sem envio de token)
parent
e497cb80
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
lib/model/network/login.dart
+3
-1
lib/model/network/login.dart
lib/view/home/home_controller.dart
+3
-14
lib/view/home/home_controller.dart
pubspec.lock
+3
-3
pubspec.lock
web/firebase-messaging-sw.js
+18
-0
web/firebase-messaging-sw.js
web/index.html
+16
-0
web/index.html
with
43 additions
and
18 deletions
+43
-18
lib/model/network/login.dart
View file @
0a60f20c
import
'package:comunicacao_hsl/model/mixin/network_basic_operations_mixin.dart'
;
import
'package:comunicacao_hsl/model/network/communication.dart'
;
import
'package:firebase_messaging/firebase_messaging.dart'
;
import
'package:flutter/foundation.dart'
;
class
LoginModel
with
NetworkBasicOperationsMixin
{
/// Singleton constructor
...
...
@@ -18,7 +19,8 @@ class LoginModel with NetworkBasicOperationsMixin {
String
?
token
;
Future
<
bool
>
connect
(
int
withMatricula
)
async
{
String
?
token
=
await
FirebaseMessaging
.
instance
.
getToken
();
String
?
token
;
if
(!
kIsWeb
)
token
=
await
FirebaseMessaging
.
instance
.
getToken
();
var
response
=
await
post
(
body:
{
"registry"
:
withMatricula
,
if
(
token
!=
null
)
"firebaseMessagingToken"
:
token
,
...
...
This diff is collapsed.
Click to expand it.
lib/view/home/home_controller.dart
View file @
0a60f20c
...
...
@@ -4,14 +4,13 @@ import 'package:comunicacao_hsl/model/network/communication.dart';
import
'package:firebase_core/firebase_core.dart'
;
import
'package:firebase_messaging/firebase_messaging.dart'
;
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
class
HomeController
{
final
ValueNotifier
<
List
<
Announcement
>>
announcements
=
ValueNotifier
([]);
final
ValueNotifier
<
bool
>
haveLoadedData
=
ValueNotifier
(
false
);
final
ValueNotifier
<
int
>
nonViewedCount
=
CommunicationModel
().
nonViewedCount
;
late
FirebaseMessaging
_messaging
;
HomeController
();
void
loadCommunications
()
{
...
...
@@ -44,10 +43,10 @@ class HomeController {
String
?
token
=
await
FirebaseMessaging
.
instance
.
getToken
();
print
(
'Firebase Messaging token:
$token
'
);
_messaging
=
FirebaseMessaging
.
instance
;
FirebaseMessaging
.
onBackgroundMessage
(
firebaseMessagingBackgroundHandler
);
NotificationSettings
settings
=
await
_messaging
.
requestPermission
(
NotificationSettings
settings
=
await
FirebaseMessaging
.
instance
.
requestPermission
(
alert:
true
,
badge:
true
,
provisional:
false
,
...
...
@@ -56,16 +55,6 @@ class HomeController {
if
(
settings
.
authorizationStatus
==
AuthorizationStatus
.
authorized
)
{
print
(
'User granted permission'
);
FirebaseMessaging
.
onMessage
.
listen
((
RemoteMessage
message
)
{
print
(
"Firebase onMessage:
${message.messageId}
${message.notification?.title}
${message.notification?.body}
"
);
});
FirebaseMessaging
.
onMessageOpenedApp
.
listen
((
RemoteMessage
message
)
{
print
(
"Firebase onMessageOpenedApp:
${message.messageId}
${message.notification?.title}
${message.notification?.body}
"
);
});
}
else
{
print
(
'User declined or has not accepted permission'
);
}
...
...
This diff is collapsed.
Click to expand it.
pubspec.lock
View file @
0a60f20c
...
...
@@ -112,7 +112,7 @@ packages:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.
7
.0"
version: "1.
8
.0"
firebase_core_platform_interface:
dependency: transitive
description:
...
...
@@ -140,14 +140,14 @@ packages:
name: firebase_messaging_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.
6
"
version: "3.0.
7
"
firebase_messaging_web:
dependency: transitive
description:
name: firebase_messaging_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.
6
"
version: "2.0.
7
"
flutter:
dependency: "direct main"
description: flutter
...
...
This diff is collapsed.
Click to expand it.
web/firebase-messaging-sw.js
0 → 100644
View file @
0a60f20c
importScripts
(
"
https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js
"
);
importScripts
(
"
https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js
"
);
firebase
.
initializeApp
({
apiKey
:
"
AIzaSyA7PR5gYMb3qNwUg6Hbyqx0Z1cebALSl1c
"
,
authDomain
:
"
comunicacaohsl-37dd1.firebaseapp.com
"
,
projectId
:
"
comunicacaohsl-37dd1
"
,
storageBucket
:
"
comunicacaohsl-37dd1.appspot.com
"
,
messagingSenderId
:
"
463039167215
"
,
appId
:
"
1:463039167215:web:835a78c252399fa7ebb91a
"
,
validKey
:
"
BETNjn_A0k_TC8u1nJOVKcV18YeXozDNfGy1Ey02NxK5WSsyO4GDcXEWapPkoEmo5H6bXua4vgm-_NoTVsJTS-k
"
,
});
const
messaging
=
firebase
.
messaging
();
messaging
.
onBackgroundMessage
((
message
)
=>
{
console
.
log
(
"
onBackgroundMessage
"
,
message
);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
web/index.html
View file @
0a60f20c
...
...
@@ -41,6 +41,21 @@
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script
src=
"https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"
></script>
<script
src=
"https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"
></script>
<script>
firebase
.
initializeApp
({
apiKey
:
"
AIzaSyA7PR5gYMb3qNwUg6Hbyqx0Z1cebALSl1c
"
,
authDomain
:
"
comunicacaohsl-37dd1.firebaseapp.com
"
,
projectId
:
"
comunicacaohsl-37dd1
"
,
storageBucket
:
"
comunicacaohsl-37dd1.appspot.com
"
,
messagingSenderId
:
"
463039167215
"
,
appId
:
"
1:463039167215:web:835a78c252399fa7ebb91a
"
,
validKey
:
"
BETNjn_A0k_TC8u1nJOVKcV18YeXozDNfGy1Ey02NxK5WSsyO4GDcXEWapPkoEmo5H6bXua4vgm-_NoTVsJTS-k
"
,
});
</script>
<script>
var
serviceWorkerVersion
=
null
;
var
scriptLoaded
=
false
;
...
...
@@ -61,6 +76,7 @@
// Wait for registration to finish before dropping the
<
script
>
tag
.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
navigator
.
serviceWorker
.
register
(
"
firebase-messaging-sw.js
"
);
var
serviceWorkerUrl
=
'
flutter_service_worker.js?v=
'
+
serviceWorkerVersion
;
navigator
.
serviceWorker
.
register
(
serviceWorkerUrl
)
.
then
((
reg
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment