Skip to content

Commit

Permalink
chore: Update version of Dart and Flutter
Browse files Browse the repository at this point in the history
Add support for null safety.
  • Loading branch information
sebas642 committed Jan 4, 2024
1 parent 14f2555 commit f950ebf
Show file tree
Hide file tree
Showing 84 changed files with 2,102 additions and 1,745 deletions.
6 changes: 3 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include: package:pedantic/analysis_options.1.9.0.yaml
include: package:flutter_lints/flutter.yaml

analyzer:
exclude: [lib/l10n/**/*.dart]
# With strong mode, generated code creates errors in VS Code even if excluded.
#strong-mode:
#implicit-casts: false
#implicit-dynamic: false
#implicit-casts: false
#implicit-dynamic: false
46 changes: 24 additions & 22 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,9 +12,10 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
Expand All @@ -21,31 +28,28 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
namespace "com.ramblenride.moto_mecanico"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

android {
compileSdkVersion 30
kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
applicationId "com.ramblenride.moto_mecanico"
minSdkVersion 16
targetSdkVersion 30
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -70,6 +74,4 @@ flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
dependencies {}
8 changes: 2 additions & 6 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
package="com.ramblenride.moto_mecanico">
<uses-permission android:name="android.permission.INTERNET"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="Moto Mecanico"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
9 changes: 4 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.10'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand All @@ -26,6 +25,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
4 changes: 1 addition & 3 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
org.gradle.jvmargs=-Xmx4G
android.useAndroidX=true
android.enableJetifier=true
android.bundle.enableUncompressedNativeLibs=false
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
34 changes: 26 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}
settings.ext.flutterSdkPath = flutterSdkPath()

includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
repositories {
google()
mavenCentral()
gradlePluginPortal()
}

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
plugins {
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
}

include ':app'
2 changes: 2 additions & 0 deletions lib/assets.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
////////////////////////////////////////////////////////////////////////
// Local assets
////////////////////////////////////////////////////////////////////////
library;

const ASSET_DIR = 'assets';
const IMG_MOTO_DEFAULT = '$ASSET_DIR/images/default-moto.jpg';
const IMG_MOTORCYCLE = '$ASSET_DIR/images/roadsign_motorcycle.png';
Expand Down
75 changes: 36 additions & 39 deletions lib/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:moto_mecanico/locale/formats.dart';
import 'package:moto_mecanico/models/distance.dart';
import 'package:package_info/package_info.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';

// This class stores the global configuration of the app.
Expand All @@ -19,57 +19,51 @@ class Configuration {
static const _PROP_VALUE_DISTANCE_UNIT_MILE = 'mile';
static const _PROP_NAME_NOTIFICATIONS = 'notifications';

SharedPreferences _prefs;
Locale _systemLocale;
// Made available to the application here, but not store in the config.
PackageInfo? packageInfo;

Locale _locale;
final Locale _systemLocale;

String _currencySymbol;
String _dateFormat;
DistanceUnit _distanceUnit;

bool _notifications;
Locale _locale;

// Made available to the application here, but not store in the config.
PackageInfo packageInfo;

Configuration(String systemLocale) {
_systemLocale = Locale(systemLocale ?? 'en');
}
SharedPreferences? _prefs;
String? _dateFormat;
DistanceUnit? _distanceUnit;

String get currencySymbol {
_currencySymbol ??=
NumberFormat.currency(locale: _systemLocale.languageCode)
.currencyName ??
_DEFAULT_CURRENCY_SYMBOL;
Configuration(String systemLocale)
: _systemLocale = Locale(systemLocale),
_currencySymbol = _DEFAULT_CURRENCY_SYMBOL,
_notifications = false,
_locale = Locale(systemLocale);

return _currencySymbol;
}
String get currencySymbol => _currencySymbol;

set currencySymbol(String symbol) {
assert(_prefs != null);
_currencySymbol = symbol;

_prefs.setString(_PROP_NAME_CURRENCY, symbol);
_prefs?.setString(_PROP_NAME_CURRENCY, symbol);
}

String get dateFormat {
if (_dateFormat == null) {
final localeDateFormat =
DateFormat.yMd(_systemLocale.languageCode).pattern;
_dateFormat =
AppLocalSupport.supportedDateFormats.contains(localeDateFormat)
? localeDateFormat
: 'y/M/d';
_dateFormat = (localeDateFormat != null &&
AppLocalSupport.supportedDateFormats.contains(localeDateFormat))
? localeDateFormat
: 'y/M/d';
}
return _dateFormat;
return _dateFormat!;
}

set dateFormat(String format) {
assert(_prefs != null);
_dateFormat = format;

_prefs.setString(_PROP_NAME_DATE_FORMAT, format);
_prefs?.setString(_PROP_NAME_DATE_FORMAT, format);
}

DistanceUnit get distanceUnit {
Expand All @@ -89,14 +83,14 @@ class Configuration {
_distanceUnit = DistanceUnit.UnitKM;
}
}
return _distanceUnit;
return _distanceUnit!;
}

set distanceUnit(DistanceUnit unit) {
assert(_prefs != null);
_distanceUnit = unit;

_prefs.setString(
_prefs?.setString(
_PROP_NAME_DISTANCE_UNIT,
unit == DistanceUnit.UnitMile
? _PROP_VALUE_DISTANCE_UNIT_MILE
Expand All @@ -108,25 +102,25 @@ class Configuration {
assert(_prefs != null);
_locale = locale;

_prefs.setString(_PROP_NAME_LOCALE, locale.languageCode);
_prefs?.setString(_PROP_NAME_LOCALE, locale.languageCode);
}

bool get notifications {
return _notifications ?? true;
return _notifications;
}

set notifications(bool enabled) {
_notifications = enabled;

_prefs.setBool(_PROP_NAME_NOTIFICATIONS, _notifications);
_prefs?.setBool(_PROP_NAME_NOTIFICATIONS, _notifications);
}

void loadConfig() async {
Future<void> loadConfig() async {
_prefs = await SharedPreferences.getInstance();
final localeStr = _prefs.getString(_PROP_NAME_LOCALE);
_locale = localeStr != null ? Locale(localeStr) : null;
final localeStr = _prefs?.getString(_PROP_NAME_LOCALE);
_locale = Locale(localeStr ?? 'en');

final distance = _prefs.getString(_PROP_NAME_DISTANCE_UNIT);
final distance = _prefs?.getString(_PROP_NAME_DISTANCE_UNIT);
if (distance != null) {
if (distance == _PROP_VALUE_DISTANCE_UNIT_KM) {
_distanceUnit = DistanceUnit.UnitKM;
Expand All @@ -135,8 +129,11 @@ class Configuration {
}
}

_currencySymbol = _prefs.getString(_PROP_NAME_CURRENCY);
_dateFormat = _prefs.getString(_PROP_NAME_DATE_FORMAT);
_notifications = _prefs.getBool(_PROP_NAME_NOTIFICATIONS);
_currencySymbol = _prefs?.getString(_PROP_NAME_CURRENCY) ??
NumberFormat.currency(locale: _systemLocale.languageCode)
.currencyName ??
_DEFAULT_CURRENCY_SYMBOL;
_dateFormat = _prefs?.getString(_PROP_NAME_DATE_FORMAT) ?? 'YY/MM/DD';
_notifications = _prefs?.getBool(_PROP_NAME_NOTIFICATIONS) ?? true;
}
}
Loading

0 comments on commit f950ebf

Please sign in to comment.