Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update example to google_sign_in ^6.0.0
Also update the index.html to the latest style, and add some changes to
make this build distinguishable from the default one (the + googleapis
bits)
  • Loading branch information
ditman committed Feb 22, 2023
commit 0d7857e52f109e023465ab7088f65b7e4a7adb8e
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final GoogleSignIn _googleSignIn = GoogleSignIn(
void main() {
runApp(
const MaterialApp(
title: 'Google Sign In',
title: 'Google Sign In + googleapis',
home: SignInDemo(),
),
);
Expand Down Expand Up @@ -149,7 +149,7 @@ class SignInDemoState extends State<SignInDemo> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Google Sign In'),
title: const Text('Google Sign In + googleapis'),
),
body: ConstrainedBox(
constraints: const BoxConstraints.expand(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ dependencies:
path: ../
flutter:
sdk: flutter
google_sign_in: ^5.1.0
googleapis: ^5.0.1
google_sign_in: ^6.0.0
googleapis: ^10.1.0
googleapis_auth: ^1.1.0

dev_dependencies:
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">
<meta name="description" content="The Google Sign In example app, using the googleapis package.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="example">
<meta name="apple-mobile-web-app-title" content="Google Sign In + googleapis">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
Expand All @@ -37,75 +37,30 @@

<!-- Google Sign In configuration -->
<meta name="google-signin-client_id" content="[YOUR_OAUTH_2_CLIENT_ID_FOR_WEB]" />
<title>Google Sign-in Example</title>
<title>Google Sign In + googleapis</title>

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<!-- 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>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}

if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
}
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "example",
"short_name": "example",
"name": "Google Sign In + googleapis",
"short_name": "gsi+googleapis",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "A new Flutter project.",
"description": "The Google Sign In example app, using the googleapis package.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
Expand Down