Skip to content

Commit

Permalink
feat: Web platform integration (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Jan 31, 2023
1 parent e2b1dc2 commit 693e922
Show file tree
Hide file tree
Showing 52 changed files with 12,574 additions and 399 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "fluttips"
}
}
2 changes: 1 addition & 1 deletion .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutterSdkVersion": "3.3.6",
"flutterSdkVersion": "3.7.0",
"flavors": {}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ service-account.json
/build/

# Web related
lib/generated_plugin_registrant.dart
.firebase

# Symbolication related
app.*.symbols
Expand Down
24 changes: 22 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
- platform: web
create_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf
base_revision: b06b8b2710955028a6b562f5aa6fe62941d6febf

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
13 changes: 7 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ PODS:
- nanopb/encode (2.30909.0)
- package_info_plus (0.4.5):
- Flutter
- path_provider_ios (0.0.1):
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- PromisesObjC (2.1.1)
- shared_preferences_foundation (0.0.1):
- Flutter
Expand All @@ -87,7 +88,7 @@ DEPENDENCIES:
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- flutter_web_browser (from `.symlinks/plugins/flutter_web_browser/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
Expand Down Expand Up @@ -126,8 +127,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_web_browser/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/ios"
sqflite:
Expand Down Expand Up @@ -157,11 +158,11 @@ SPEC CHECKSUMS:
GoogleUtilities: bad72cb363809015b1f7f19beb1f1cd23c589f95
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
url_launcher_ios: ae1517e5e344f5544fb090b079e11f399dfbe4d2
webview_flutter_wkwebview: b7e70ef1ddded7e69c796c7390ee74180182971f

PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
Expand Down
4 changes: 3 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -249,6 +249,7 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -263,6 +264,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
1 change: 0 additions & 1 deletion ios/build/.last_build_id

This file was deleted.

54 changes: 46 additions & 8 deletions lib/core/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ abstract class Config {
static const debugMode = kDebugMode;
static const firebaseEnabled = !debugMode;
static const analyticsEnabled = !debugMode;
static const crashlyticsEnabled = !debugMode;
static bool bugseeEnabled = !debugMode && _environment == Environments.dev;

// TODO: Add alternative for web
static const crashlyticsEnabled = !kIsWeb && !debugMode;
static bool bugseeEnabled =
!kIsWeb && !debugMode && _environment == Environments.dev;

static const String _environmentFolder = 'environments';
static final num maxDatabaseIntValue = pow(2, 32) - 1;
Expand Down Expand Up @@ -75,6 +78,10 @@ abstract class Config {
static String? firebaseIosIosBundleId;
static String? firebaseAndroidApiKey;
static String? firebaseAndroidAppId;
static String? firebaseWebApiKey;
static String? firebaseWebAppId;
static String? firebaseWebAuthDomain;
static String? firebaseWebMeasurementId;
static final _environment = enumFromString(
Environments.values,
const String.fromEnvironment('ENV'),
Expand All @@ -87,12 +94,15 @@ abstract class Config {
}

static void _initializeEnvVariables() {
if (Platform.isAndroid) {
bugseeAPIKey =
_EnvConfig.getEnvVariable(_EnvConfig.ENV_KEY_BUGSEE_ANDROID_API_KEY);
} else if (Platform.isIOS) {
bugseeAPIKey =
_EnvConfig.getEnvVariable(_EnvConfig.ENV_KEY_BUGSEE_IOS_API_KEY);
if (!kIsWeb) {
if (Platform.isAndroid) {
bugseeAPIKey = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_BUGSEE_ANDROID_API_KEY,
);
} else if (Platform.isIOS) {
bugseeAPIKey =
_EnvConfig.getEnvVariable(_EnvConfig.ENV_KEY_BUGSEE_IOS_API_KEY);
}
}
_initializeFirebaseEnvVariables();
}
Expand Down Expand Up @@ -125,6 +135,18 @@ abstract class Config {
firebaseAndroidAppId = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_FIREBASE_ANDROID_APP_ID,
);
firebaseWebApiKey = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_FIREBASE_WEB_API_KEY,
);
firebaseWebAppId = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_FIREBASE_WEB_APP_ID,
);
firebaseWebAuthDomain = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_FIREBASE_WEB_AUTH_DOMAIN,
);
firebaseWebMeasurementId = _EnvConfig.getEnvVariable(
_EnvConfig.ENV_KEY_FIREBASE_WEB_MEASUREMENT_ID,
);
}
}

Expand All @@ -150,6 +172,12 @@ abstract class _EnvConfig {
static const ENV_KEY_FIREBASE_ANDROID_API_KEY = 'FIREBASE_ANDROID_API_KEY';
static const ENV_KEY_FIREBASE_ANDROID_APP_ID = 'FIREBASE_ANDROID_APP_ID';

static const ENV_KEY_FIREBASE_WEB_API_KEY = 'FIREBASE_WEB_API_KEY';
static const ENV_KEY_FIREBASE_WEB_APP_ID = 'FIREBASE_WEB_APP_ID';
static const ENV_KEY_FIREBASE_WEB_AUTH_DOMAIN = 'FIREBASE_WEB_AUTH_DOMAIN';
static const ENV_KEY_FIREBASE_WEB_MEASUREMENT_ID =
'FIREBASE_WEB_MEASUREMENT_ID';

static const systemEnv = {
ENV_KEY_BUGSEE_IOS_API_KEY:
String.fromEnvironment(ENV_KEY_BUGSEE_IOS_API_KEY),
Expand Down Expand Up @@ -179,6 +207,16 @@ abstract class _EnvConfig {
String.fromEnvironment(ENV_KEY_FIREBASE_ANDROID_API_KEY),
ENV_KEY_FIREBASE_ANDROID_APP_ID:
String.fromEnvironment(ENV_KEY_FIREBASE_ANDROID_APP_ID),

// Firebase Android
ENV_KEY_FIREBASE_WEB_API_KEY:
String.fromEnvironment(ENV_KEY_FIREBASE_WEB_API_KEY),
ENV_KEY_FIREBASE_WEB_APP_ID:
String.fromEnvironment(ENV_KEY_FIREBASE_WEB_APP_ID),
ENV_KEY_FIREBASE_WEB_AUTH_DOMAIN:
String.fromEnvironment(ENV_KEY_FIREBASE_WEB_AUTH_DOMAIN),
ENV_KEY_FIREBASE_WEB_MEASUREMENT_ID:
String.fromEnvironment(ENV_KEY_FIREBASE_WEB_MEASUREMENT_ID),
};

static final Map<String, String> _envFileEnv = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/core/common/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:logger/logger.dart';
import 'package:stack_trace/stack_trace.dart';

abstract class Logger {
static final CrashReportTool _crashReportTool = Config.firebaseEnabled
static final CrashReportTool _crashReportTool = Config.crashlyticsEnabled
? CrashlyticsCrashReportTool()
: NoOpsCrashReportTool();

Expand Down
23 changes: 22 additions & 1 deletion lib/core/source/database.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'dart:async';
import 'dart:io';
import 'package:floor/floor.dart';
import 'package:flutter/foundation.dart';
import 'package:fluttips/core/model/db/tip_db_entity.dart';
import 'package:fluttips/core/source/local_source/converters/date_time_converter.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:fluttips/core/source/local_source/tips_local_source.dart';
import 'package:sqflite/sqflite.dart' as sqflite;
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';

part 'database.g.dart';

Expand All @@ -14,3 +18,20 @@ abstract class AppDatabase extends FloorDatabase {

Future<void> clearAllTables() => database.delete(TipDbEntity.tableName);
}

// Used by database.g.dart to provide the web impl
// Depends on https://github.com/pinchbv/floor/pull/730/files
final sqflite.DatabaseFactory sqfliteDatabaseFactory = () {
if (kIsWeb) {
return databaseFactoryFfiWeb;
} else if (Platform.isAndroid || Platform.isIOS) {
return sqflite.databaseFactory;
} else if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
sqfliteFfiInit();
return databaseFactoryFfi;
} else {
throw UnsupportedError(
'Platform ${Platform.operatingSystem} is not supported by Floor.',
);
}
}();
18 changes: 12 additions & 6 deletions lib/firebase_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import 'package:fluttips/core/common/config.dart';
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
Expand All @@ -45,12 +42,21 @@ class DefaultFirebaseOptions {
);
case TargetPlatform.fuchsia:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for fuchsia - '
'you can reconfigure this by running the FlutterFire CLI again.',
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}

static FirebaseOptions web = FirebaseOptions(
apiKey: Config.firebaseWebApiKey!,
appId: Config.firebaseWebAppId!,
authDomain: Config.firebaseWebAuthDomain!,
measurementId: Config.firebaseWebMeasurementId!,
messagingSenderId: Config.firebaseMessagingSenderId!,
projectId: Config.firebaseProjectId!,
storageBucket: Config.firebaseStorageBucket!,
);

static FirebaseOptions android = FirebaseOptions(
apiKey: Config.firebaseAndroidApiKey!,
appId: Config.firebaseAndroidAppId!,
Expand Down
1 change: 1 addition & 0 deletions lib/ui/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ part 'app_router.gr.dart';
AutoRoute(
name: 'UserOnboardedRouter',
page: SectionRouter,
path: '',
children: [
AutoRoute(
page: HomeScreen,
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/app_router.gr.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/ui/common/app_base_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppBaseButton extends StatelessWidget {
),
elevation: 5,
color: backgroundColor,
padding: EdgeInsets.symmetric(vertical: 14.h, horizontal: 17.w),
textColor: textColor,
onPressed: onPressed,
child: Row(
Expand All @@ -37,7 +38,9 @@ class AppBaseButton extends StatelessWidget {
children: [
if (image != null)
Container(
padding: EdgeInsets.only(right: 10.w),
width: 22.w,
height: 22.w,
margin: EdgeInsets.only(right: 10.w),
child: image,
),
Text(text),
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/helper/launch_helper.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:url_launcher/url_launcher.dart';

Future<void> openYoutubePlaylist(String playlistId) async {
final url = 'www.youtube.com/playlist?list=$playlistId';
final youtubeWebUri = Uri.parse('https://$url');
if (Platform.isIOS) {
if (kIsWeb || !Platform.isIOS) {
await launchUrl(youtubeWebUri);
} else {
if (await canLaunchUrl(Uri.parse('youtube://$url'))) {
await launchUrl(
Uri.parse('youtube://$url'),
Expand All @@ -17,7 +20,5 @@ Future<void> openYoutubePlaylist(String playlistId) async {
throw Exception('Could not launch https://$url');
}
}
} else {
await launchUrl(youtubeWebUri);
}
}
Loading

0 comments on commit 693e922

Please sign in to comment.