removed constants from env to the separate file

This commit is contained in:
Vadim 2024-02-19 17:11:54 +01:00
parent bc6d01f87c
commit 98523055aa
12 changed files with 40 additions and 39 deletions

View file

@ -67,12 +67,10 @@ jobs:
cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app
- name: Restore firebase_options.dart
env:
FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }}
run: |
FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart
echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH
cp $FIREBASE_OPTIONS_PATH ./lib
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart"
- name: Restore constants.dart
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart"
- name: Install Flutter
uses: subosito/flutter-action@v2

View file

@ -66,6 +66,9 @@ jobs:
- name: Restore firebase_options.dart
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart"
- name: Restore constants.dart
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart"
- name: Install Flutter
uses: subosito/flutter-action@v2
with:

View file

@ -86,12 +86,10 @@ jobs:
cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app
- name: Restore firebase_options.dart
env:
FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }}
run: |
FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart
echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH
cp $FIREBASE_OPTIONS_PATH ./lib
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.FIREBASE_OPTIONS }}" "lib/firebase_options.dart"
- name: Restore constants.dart
run: bash .github/scripts/restore_from_base64.sh "${{ secrets.CONSTANTS }}" "lib/constants.dart"
# This step makes sense when Github release is enabled because this release increments the build number.
# Therefore here we have to increment it as well to build an apk with the same build number.

1
.gitignore vendored
View file

@ -58,6 +58,7 @@ android/app/google-services.json
ios/firebase_app_id_file.json
ios/Runner/GoogleService-Info.plist
/lib/firebase_options.dart
/lib/constants.dart
coverage/
test/coverage_helper_test.dart

View file

@ -38,6 +38,19 @@ To build this app you need to install Flutter 3.10.0 stable. [How to install](ht
### 2. Project setup
#### Restore _constants.dart_ file
Create a file _lib/constants.dart_ and paste the following content:
```dart
const String contactEmail = '';
const String iapServerUrl = '';
const String issuesReportUrl = '';
const String sourceCodeUrl = '';
```
#### Stub IAP package
As part of the app's functionallity is in the private repo, you have to replace these lines in _pubspec.yaml_:
```yaml

View file

@ -2,9 +2,10 @@ import 'package:flutter/material.dart';
import 'package:m3_lightmeter_iap/src/data/models/iap_product.dart';
class IAPProductsProvider extends StatefulWidget {
final String apiUrl;
final Widget child;
const IAPProductsProvider({required this.child, super.key});
const IAPProductsProvider({required this.apiUrl, required this.child, super.key});
static IAPProductsProviderState of(BuildContext context) => IAPProductsProvider.maybeOf(context)!;

View file

@ -2,39 +2,23 @@ enum BuildType { dev, prod }
class Environment {
final BuildType buildType;
final String sourceCodeUrl;
final String issuesReportUrl;
final String contactEmail;
final bool hasLightSensor;
const Environment({
required this.buildType,
required this.sourceCodeUrl,
required this.issuesReportUrl,
required this.contactEmail,
this.hasLightSensor = false,
});
const Environment.dev()
: buildType = BuildType.dev,
sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter',
issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues/new/choose',
contactEmail = 'contact.vodemn@gmail.com',
hasLightSensor = false;
const Environment.prod()
: buildType = BuildType.prod,
sourceCodeUrl = 'https://github.com/vodemn/m3_lightmeter',
issuesReportUrl = 'https://github.com/vodemn/m3_lightmeter/issues/new/choose',
contactEmail = 'contact.vodemn@gmail.com',
hasLightSensor = false;
Environment copyWith({bool? hasLightSensor}) => Environment(
buildType: buildType,
sourceCodeUrl: sourceCodeUrl,
issuesReportUrl: issuesReportUrl,
contactEmail: contactEmail,
hasLightSensor: hasLightSensor ?? this.hasLightSensor,
);
}

View file

@ -4,6 +4,7 @@ import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/widgets.dart';
import 'package:lightmeter/application.dart';
import 'package:lightmeter/application_wrapper.dart';
import 'package:lightmeter/constants.dart';
import 'package:lightmeter/data/analytics/analytics.dart';
import 'package:lightmeter/data/analytics/api/analytics_firebase.dart';
import 'package:lightmeter/environment.dart';
@ -27,7 +28,10 @@ Future<void> runLightmeterApp(Environment env) async {
products: [IAPProduct(storeId: IAPProductType.paidFeatures.storeId)],
child: application,
)
: IAPProductsProvider(child: application),
: IAPProductsProvider(
apiUrl: iapServerUrl,
child: application,
),
);
},
_errorsLogger.logCrash,

View file

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/constants.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:url_launcher/url_launcher.dart';
class ReportIssueListTile extends StatelessWidget {
@ -13,7 +13,7 @@ class ReportIssueListTile extends StatelessWidget {
title: Text(S.of(context).reportIssue),
onTap: () {
launchUrl(
Uri.parse(ServicesProvider.of(context).environment.issuesReportUrl),
Uri.parse(issuesReportUrl),
mode: LaunchMode.externalApplication,
);
},

View file

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/constants.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:url_launcher/url_launcher.dart';
class SourceCodeListTile extends StatelessWidget {
@ -13,7 +13,7 @@ class SourceCodeListTile extends StatelessWidget {
title: Text(S.of(context).sourceCode),
onTap: () {
launchUrl(
Uri.parse(ServicesProvider.of(context).environment.sourceCodeUrl),
Uri.parse(sourceCodeUrl),
mode: LaunchMode.externalApplication,
);
},

View file

@ -1,7 +1,7 @@
import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:lightmeter/constants.dart';
import 'package:lightmeter/generated/l10n.dart';
import 'package:lightmeter/providers/services_provider.dart';
import 'package:url_launcher/url_launcher.dart';
class WriteEmailListTile extends StatelessWidget {
@ -13,8 +13,7 @@ class WriteEmailListTile extends StatelessWidget {
leading: const Icon(Icons.email),
title: Text(S.of(context).writeEmail),
onTap: () {
final email = ServicesProvider.of(context).environment.contactEmail;
final mailToUrl = Uri.parse('mailto:$email?subject=M3 Lightmeter');
final mailToUrl = Uri.parse('mailto:$contactEmail?subject=M3 Lightmeter');
canLaunchUrl(mailToUrl).then((canLaunch) {
if (canLaunch) {
launchUrl(
@ -29,7 +28,7 @@ class WriteEmailListTile extends StatelessWidget {
action: SnackBarAction(
label: S.of(context).copyEmail,
onPressed: () {
FlutterClipboard.copy(email).then((_) {
FlutterClipboard.copy(contactEmail).then((_) {
ScaffoldMessenger.of(context).clearSnackBars();
});
},

View file

@ -28,7 +28,7 @@ dependencies:
m3_lightmeter_iap:
git:
url: "https://github.com/vodemn/m3_lightmeter_iap"
ref: v0.8.0
ref: v0.8.1
m3_lightmeter_resources:
git:
url: "https://github.com/vodemn/m3_lightmeter_resources"