From aa496b0ed2e0959947e22d62c797e6ba2a6c63f5 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Tue, 14 Aug 2018 09:41:03 +0200 Subject: [PATCH] Added package_info to get the package version --- lib/globals.dart | 5 +-- lib/mainCommon.dart | 85 +++++++++++++++++++++++++-------------------- pubspec.yaml | 4 +-- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/lib/globals.dart b/lib/globals.dart index 26c3dc4..e05d647 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,10 +1,11 @@ library fires.globals; +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'dart:async'; -final String appVersion = '1.6'; +String appVersion; final Widget appMediumIcon = Image.asset('images/logo-200.png', width: 60.0, height: 60.0); diff --git a/lib/mainCommon.dart b/lib/mainCommon.dart index fe5976d..3418eaf 100644 --- a/lib/mainCommon.dart +++ b/lib/mainCommon.dart @@ -12,6 +12,12 @@ import 'models/appState.dart'; import 'models/firesApi.dart'; import 'redux/fetchDataMiddleware.dart'; import 'redux/reducers.dart'; +import 'package:package_info/package_info.dart'; + +Future loadPackageInfo() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + return packageInfo; +} Future> loadSecrets() async { return await SecretLoader(secretPath: 'assets/private-settings.json').load(); @@ -20,49 +26,54 @@ Future> loadSecrets() async { void mainCommon(List> otherMiddleware) { final injector = Injector.getInjector(); injector.map((i) => new FiresApi(), isSingleton: true); - loadSecrets().then((secrets) { - final store = new Store(appStateReducer, + loadPackageInfo().then((packageInfo) { + globals.appVersion = packageInfo.version; + print('Running version ${packageInfo.version}'); + loadSecrets().then((secrets) { + final store = new Store(appStateReducer, initialState: new AppState( - gmapKey: secrets['gmapKey'], - firesApiKey: secrets['firesApiKey'], - serverUrl: secrets['firesApiUrl'], - firesApiUrl: secrets['firesApiUrl'] + "api/v1/"), - middleware: List.from(otherMiddleware)..add(fetchDataMiddleware)); + gmapKey: secrets['gmapKey'], + firesApiKey: secrets['firesApiKey'], + serverUrl: secrets['firesApiUrl'], + firesApiUrl: secrets['firesApiUrl'] + "api/v1/"), + middleware: List.from(otherMiddleware) + ..add(fetchDataMiddleware)); - injector.map>((i) => store); - injector.map((i) => store.state.firesApiUrl, key: "firesApiUrl"); - injector.map((i) => store.state.firesApiKey, key: "firesApiKey"); - injector.map((i) => store.state.serverUrl, key: "serverUrl"); - injector.map((i) => store.state.gmapKey, key: "gmapKey"); + injector.map>((i) => store); + injector.map((i) => store.state.firesApiUrl, key: "firesApiUrl"); + injector.map((i) => store.state.firesApiKey, key: "firesApiKey"); + injector.map((i) => store.state.serverUrl, key: "serverUrl"); + injector.map((i) => store.state.gmapKey, key: "gmapKey"); - var useSentry = !globals.isDevelopment; + var useSentry = !globals.isDevelopment; - SentryClient _sentry; - if (useSentry) _sentry = SentryClient(dsn: secrets['sentryDSN']); + SentryClient _sentry; + if (useSentry) _sentry = SentryClient(dsn: secrets['sentryDSN']); - // https://flutter.io/cookbook/maintenance/error-reporting/ - runZoned>(() async { - runApp(new FiresApp(store)); - }, onError: (error, stackTrace) { - // Whenever an error occurs, call the `_reportError` function. This will send - // Dart errors to our dev console or Sentry depending on the environment. - _reportError(useSentry, _sentry, error, stackTrace); + // https://flutter.io/cookbook/maintenance/error-reporting/ + runZoned>(() async { + runApp(new FiresApp(store)); + }, onError: (error, stackTrace) { + // Whenever an error occurs, call the `_reportError` function. This will send + // Dart errors to our dev console or Sentry depending on the environment. + _reportError(useSentry, _sentry, error, stackTrace); + }); + + // Listen to store changes, and re-render when the state is updated + store.onChange.listen((state) { + // print('Store onChange'); + }); + FlutterError.onError = (FlutterErrorDetails details) { + if (!useSentry) { + // In development mode simply print to console. + FlutterError.dumpErrorToConsole(details); + } else { + // In production mode report to the application zone to report to + // Sentry. + Zone.current.handleUncaughtError(details.exception, details.stack); + } + }; }); - - // Listen to store changes, and re-render when the state is updated - store.onChange.listen((state) { - // print('Store onChange'); - }); - FlutterError.onError = (FlutterErrorDetails details) { - if (!useSentry) { - // In development mode simply print to console. - FlutterError.dumpErrorToConsole(details); - } else { - // In production mode report to the application zone to report to - // Sentry. - Zone.current.handleUncaughtError(details.exception, details.stack); - } - }; }); } diff --git a/pubspec.yaml b/pubspec.yaml index 9bcbcdf..3f2301e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,6 +18,7 @@ dependencies: sentry: "^2.0.2" flutter_markdown: "^0.1.5" url_launcher: "^3.0.2" + package_info: "^0.3.2" # net http: "^0.11.3+16" @@ -62,9 +63,6 @@ dependencies: cupertino_icons: "^0.1.2" community_material_icon: "^0.1.2" - # not using yet - # package_info: "^0.3.2" - dev_dependencies: flutter_test: sdk: flutter