Skip to content

Commit

Permalink
Merge pull request #308 from invest-it/linum-230-implement-env-enviro…
Browse files Browse the repository at this point in the history
…nment

Implemented dotenv environment & Add Wiredash Bug Reporting Functionality
  • Loading branch information
NightmindOfficial authored Jul 13, 2024
2 parents 50fd433 + 1ca524b commit 5700ab6
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 35 deletions.
25 changes: 25 additions & 0 deletions .env.vault
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#/-------------------.env.vault---------------------/
#/ cloud-agnostic vaulting standard /
#/ [how it works](https://dotenv.org/env-vault) /
#/--------------------------------------------------/

# development
DOTENV_VAULT_DEVELOPMENT="3A5tZDO2VDHgpFhdmANOWg4UBJGceN5vWXWY+TnaLc4VUP99gDwEG9OaRC8UOZDtdnuY83xfmvc3fwLcMQiufIuRC8us/CVmG7P8OvNYMk84t58ixNi4656PpSmUvl/dIEtC4XP1g2O2su93EGnahp+w8Pg77TcupFJU6UEJNd4OgvBXk6Mujr0EXRvMRuEXp0WAnCpkypWOKj99Jsutkh3GE9geloGy"
DOTENV_VAULT_DEVELOPMENT_VERSION=12

# ci
DOTENV_VAULT_CI="l4QaivRahkpJqtkiZw+71Jw2wuX77buN+a0ICh5YGoeaXHJ8AXdJE7XQoAjN+cHzLMwMqqKO8QF5r69oVLVbeHo0Do/Jg4wwWtgrCLUJHw1evVrM5z0JWyqEh56wnp7puVMu14DBTqQ5kA=="
DOTENV_VAULT_CI_VERSION=5

# staging
DOTENV_VAULT_STAGING="vJOG+kCLhGQuU5S9zzlIfNs6qQUwgZ5JUrVx+fNO2lS0PKbBdMIo6I3MpHv6Aaiuw0W7GFfKUP7zd2NKisRf6OT9QjJW5pq4pXaSTXCFmJQJtZAi+vWiuS9bhppSwhzW8W173RR8XDjtja+VTGIr1KFoDniYtq3uYiY6736CJ+3emssiLq0xnpO5p74EMldx5Xx4Xjs3jm47CrNqJHkj84dQWekDJB+F6SNXxkNpZLMWfTQYxmtpYOqL/ipXKGWk9wd5EIEgLT2Y01RSZNu9THsJ0MI/Cjhg3ZfpehtyFGHIUtpA7bjpZdVllEH8//M22vVZvs3iEEcIw2FyKzcv5g=="
DOTENV_VAULT_STAGING_VERSION=8

# production
DOTENV_VAULT_PRODUCTION="yX+vDD9X8QtDIbnXKTmezSoKSnQg3LbbdtCaVAZM+jzvxj5YKFsH8dHhyLilxv2y5f+VlQVfIaMmRT/Vz5ty3PsPBHBR+gx7sJAJv4juI8WAX19GCibqSNwRrWv1Z1G9+iFcFAKXL/BIXjo+AseecqQuHBCktvTK8bayHLpMq67N1HjzXtZPfDwlQASsh/Py6HkNMg2jxZbvLi9n6lfce8JCMeSLr8pF5q0QMDS8cw28c3E/aZF8tC/FU02fraDwVtRcEU9blb9s"
DOTENV_VAULT_PRODUCTION_VERSION=6

#/----------------settings/metadata-----------------/
DOTENV_VAULT="vlt_15ab51d92700564bd249eb93c98979af499b09328bf016b631d6dceefea6df19"
DOTENV_API_URL="https://vault.dotenv.org"
DOTENV_CLI="npx dotenv-vault@latest"
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ firebase_app_id_file.json
# Mocks for Testing
# TODO ignore mocks again
#*.mocks.dart

# DOTENV Integration
.env*
.flaskenv*
!.env.project
!.env.vault


# Don't upload Node Modules
/node_modules/
29 changes: 29 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// build.js
require('dotenv').config()


const fs = require('fs');
const path = require('path');

// Ensure .env variables are loaded
if (!process.env) {
console.error('Failed to load environment variables');
process.exit(1);
}

// Convert loaded environment variables to .env file format
const envContent = Object.keys(process.env)
.map(key => `${key}=${process.env[key]}`)
.join('\n');

// Path to the .env file in your Flutter project
const envPath = path.join(__dirname, '.env');

// Write the .env file
fs.writeFileSync(envPath, envContent);
console.log('.env file written');



console.log(`Three Words. Thirteen letters. Say it, and I'm yours: ${process.env.HELLOWORLD}`)
console.log(`Sentry: ${process.env.SENTRY}`) // Remove after check
8 changes: 8 additions & 0 deletions lib/core/design/layout/widgets/app_bar_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:linum/core/navigation/get_delegate.dart';
import 'package:linum/core/navigation/main_routes.dart';
import 'package:logger/logger.dart';
import 'package:wiredash/wiredash.dart';

const Color lipContextColor = Color(
0xFFC1E695,
Expand Down Expand Up @@ -38,6 +39,12 @@ abstract class AppBarAction {
),
);
},
DefaultAction.bugreport: (BuildContext context) {
return AppBarAction.fromParameters(
icon: Icons.bug_report_rounded,
ontap: () => Wiredash.of(context).show(inheritMaterialTheme: true),
);
},
DefaultAction.settings: (BuildContext context) {
return AppBarAction.fromParameters(
icon: Icons.settings_rounded,
Expand Down Expand Up @@ -75,6 +82,7 @@ abstract class AppBarAction {

enum DefaultAction {
academy,
bugreport,
notification,
filter,
back,
Expand Down
10 changes: 3 additions & 7 deletions lib/core/design/layout/widgets/lip_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import 'package:flutter/material.dart';
import 'package:linum/core/design/layout/enums/screen_fraction_enum.dart';
import 'package:linum/core/design/layout/utils/layout_helpers.dart';




class LipSection extends StatelessWidget {
final String lipTitle;
final bool isInverted;
Expand Down Expand Up @@ -64,7 +61,7 @@ class LipSection extends StatelessWidget {
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
leading: leadingAction!(context),
leading: leadingAction?.call(context),
actions: _actionHelper(actions, context),
),
),
Expand All @@ -84,8 +81,7 @@ class LipSection extends StatelessWidget {
color: Theme.of(context).colorScheme.primary,
child: Baseline(
baselineType: TextBaseline.alphabetic,
baseline:
context.proportionateScreenHeight(164) - 12,
baseline: context.proportionateScreenHeight(164) - 12,
child: Text(
lipTitle,
textAlign: TextAlign.center,
Expand All @@ -106,7 +102,7 @@ class LipSection extends StatelessWidget {
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
leading: leadingAction!(context),
leading: leadingAction?.call(context),
actions: _actionHelper(actions, context),
),
),
Expand Down
62 changes: 50 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:linum/app.dart';
import 'package:linum/core/localization/settings/constants/supported_locales.dart';
import 'package:linum/core/navigation/main_route_information_parser.dart';
import 'package:linum/core/navigation/main_router_delegate.dart';
import 'package:linum/core/navigation/main_routes.dart';
import 'package:linum/generated/objectbox/objectbox.g.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:wiredash/wiredash.dart';

Future<void> main({bool? testing}) async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -28,20 +31,42 @@ Future<void> main({bool? testing}) async {

// Force Portrait Mode
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SharedPreferences.getInstance().then((pref) {
runApp(
LifecycleWatcher(store: store, testing: testing, preferences: pref),
);
});

// Load .env
await dotenv.load();

final pref = await SharedPreferences.getInstance();

FlutterError.onError = (details) async {
await Sentry.captureException(details.exception, stackTrace: details.stack);
FlutterError.presentError(details);
};

await SentryFlutter.init(
(options) {
options.dsn = dotenv.env['SENTRY_DSN'];
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
options.diagnosticLevel = SentryLevel.warning;
},
);

runApp(
LifecycleWatcher(store: store, testing: testing, preferences: pref),
);
}

/// Wrapper to handle global lifecycle changes, for example the app closing.
class LifecycleWatcher extends StatefulWidget {
final Store store;
final bool? testing;
final SharedPreferences preferences;
const LifecycleWatcher({super.key, required this.store, this.testing, required this.preferences});
const LifecycleWatcher({
super.key,
required this.store,
this.testing,
required this.preferences,
});

@override
State<LifecycleWatcher> createState() => _LifecycleWatcherState();
Expand All @@ -54,18 +79,31 @@ class _LifecycleWatcherState extends State<LifecycleWatcher> {
defaultRoute: MainRoute.home,
);

final MainRouteInformationParser routeInformationParser = MainRouteInformationParser();
final MainRouteInformationParser routeInformationParser =
MainRouteInformationParser();
// print("Rebuild LifecycleWatcher");
return EasyLocalization(
supportedLocales: supportedLocales,
path: 'assets/lang',
fallbackLocale: const Locale('de', 'DE'),
child: Linum(
return Wiredash(
feedbackOptions: const WiredashFeedbackOptions(
labels: [
Label(id: 'label-ztqz1iic2d', title: 'Bug'),
Label(id: 'label-vc1hsuuyj3', title: 'Improvement'),
Label(id: 'label-eobuukbzgi', title: 'Praise'),
],
),
projectId: dotenv.env[
'WIREDASH_PROJECT_ID']!, //FUTURE Check if the null checks can cause issues and rewrite if necessary
secret: dotenv.env['WIREDASH_SECRET']!,
child: EasyLocalization(
supportedLocales: supportedLocales,
path: 'assets/lang',
fallbackLocale: const Locale('de', 'DE'),
child: Linum(
store: widget.store,
routerDelegate: routerDelegate,
routeInformationParser: routeInformationParser,
testing: widget.testing,
preferences: widget.preferences,
),
),
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/screens/budget_screen/budget_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class BudgetScreen extends StatelessWidget {
return ScreenSkeleton(
head: 'Budget',
leadingAction: AppBarAction.fromPreset(DefaultAction.academy),
actions: [
AppBarAction.fromPreset(
DefaultAction.bugreport,
),
],
body: Column(
children: [
Row(
Expand Down
27 changes: 16 additions & 11 deletions lib/screens/home_screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import 'package:linum/screens/home_screen/widgets/home_screen_listview.dart';
import 'package:linum/screens/lock_screen/services/pin_code_service.dart';
import 'package:provider/provider.dart';



/// Page Index: 0
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
Expand All @@ -42,8 +40,7 @@ class _HomeScreenState extends State<HomeScreen> {

void resetAlgorithmProvider() {
// TODO: read how the Widget is re-rendered here
final AlgorithmService algorithmProvider =
context.read<AlgorithmService>();
final AlgorithmService algorithmProvider = context.read<AlgorithmService>();

if (algorithmProvider.state.filter == Filters.noFilter) {
algorithmProvider.resetCurrentShownMonth();
Expand All @@ -57,8 +54,7 @@ class _HomeScreenState extends State<HomeScreen> {

@override
Widget build(BuildContext context) {
final PinCodeService pinCodeProvider =
context.watch<PinCodeService>();
final PinCodeService pinCodeProvider = context.watch<PinCodeService>();

resetAlgorithmProvider();

Expand All @@ -77,6 +73,7 @@ class _HomeScreenState extends State<HomeScreen> {
key: const Key("pinRecallButton"),
),
AppBarAction.fromPreset(DefaultAction.settings),
AppBarAction.fromPreset(DefaultAction.bugreport),
],
screenCard: HomeScreenCard(
controller: _flipCardController!,
Expand All @@ -98,13 +95,17 @@ class _HomeScreenState extends State<HomeScreen> {
DropdownMenuItem<bool>(
value: false,
child: Text(
tr(translationKeys.homeScreen.labelRecentTransactions),
tr(translationKeys
.homeScreen.labelRecentTransactions,
),
),
),
DropdownMenuItem<bool>(
value: true,
child: Text(
tr(translationKeys.homeScreen.labelActiveSerialcontracts),
tr(translationKeys
.homeScreen.labelActiveSerialcontracts,
),
),
),
],
Expand All @@ -125,12 +126,16 @@ class _HomeScreenState extends State<HomeScreen> {
),
TextButton(
onPressed: () {
context.getMainRouterDelegate().pushRoute(MainRoute.filter);
context
.getMainRouterDelegate()
.pushRoute(MainRoute.filter);
},
child: Text(
showRepeatables
? tr(translationKeys.homeScreen.buttonShowAll).toUpperCase()
: tr(translationKeys.homeScreen.buttonShowMore).toUpperCase(),
? tr(translationKeys.homeScreen.buttonShowAll)
.toUpperCase()
: tr(translationKeys.homeScreen.buttonShowMore)
.toUpperCase(),
style: Theme.of(context).textTheme.labelSmall?.copyWith(
color: Theme.of(context).colorScheme.primary,
fontSize: 14,
Expand Down
21 changes: 16 additions & 5 deletions lib/screens/settings_screen/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:linum/core/authentication/presentation/widgets/logout_button.dar
import 'package:linum/core/authentication/presentation/widgets/logout_form.dart';
import 'package:linum/core/categories/settings/presentation/widgets/standard_category_selectors.dart';
import 'package:linum/core/design/layout/enums/screen_key.dart';
import 'package:linum/core/design/layout/widgets/app_bar_action.dart';
import 'package:linum/core/design/layout/widgets/screen_skeleton.dart';
import 'package:linum/core/localization/settings/presentation/widgets/language_selector.dart';
import 'package:linum/features/currencies/settings/presentation/widgets/standard_currency_selector.dart';
Expand All @@ -31,6 +32,9 @@ class SettingsScreen extends StatelessWidget {
isInverted: true,
screenKey: ScreenKey.settings,
initialActionLipBody: Container(),
actions: [
AppBarAction.fromPreset(DefaultAction.bugreport),
],
body: Column(
children: [
LogoutForm(),
Expand All @@ -44,11 +48,11 @@ class SettingsScreen extends StatelessWidget {
vertical: 24.0,
),
children: [

/// STANDARD CATEGORY
const ListHeader(
'settings_screen.standard-category.label-title',
tooltipMessage: 'settings_screen.standard-category.label-tooltip',
tooltipMessage:
'settings_screen.standard-category.label-tooltip',
),
const StandardCategorySelectors(),
const ListDivider(),
Expand All @@ -61,7 +65,9 @@ class SettingsScreen extends StatelessWidget {
const PinSwitch(),
const ListDivider(),

const ListHeader('settings_screen.standard-currency.label-title'),
const ListHeader(
'settings_screen.standard-currency.label-title',
),
const StandardCurrencySelector(),
const ListDivider(),

Expand All @@ -73,14 +79,19 @@ class SettingsScreen extends StatelessWidget {
const ListDivider(),

/// YOUR ACCOUNT
const ListHeader('settings_screen.system-settings.label-title'),
const SizedBox(height: 16.0,),
const ListHeader(
'settings_screen.system-settings.label-title',
),
const SizedBox(
height: 16.0,
),
const Wrap(
spacing: 8.0,
children: [
LogoutButton(),
ForgotPasswordButton(ScreenKey.settings),
ChangeEmailButton(ScreenKey.settings),
//TODO add ReportBugButton(),
DeleteUserButton(),
],
),
Expand Down
Loading

0 comments on commit 5700ab6

Please sign in to comment.