From db53d3fd711eacc651ea1721f38235eb33b7cdd4 Mon Sep 17 00:00:00 2001 From: Tensor-Programming Date: Fri, 25 Jan 2019 20:58:15 -0500 Subject: [PATCH 1/5] update for dart 2.0 and geolocator --- .../plugins/GeneratedPluginRegistrant.java | 8 +- android/gradlew | 320 +++++++++--------- android/local.properties | 4 +- ios/Flutter/Generated.xcconfig | 3 +- ios/Runner/GeneratedPluginRegistrant.m | 8 +- lib/const.dart | 2 +- lib/json/response.g.dart | 312 ++++++++--------- lib/l10n/intl_messages.arb | 28 +- lib/l10n/messages_all.dart | 138 ++++---- lib/l10n/messages_en.dart | 50 +-- lib/l10n/messages_es.dart | 52 +-- lib/l10n/messages_ja.dart | 50 +-- lib/l10n/messages_messages.dart | 50 +-- lib/main.dart | 41 +-- lib/model/model_command.dart | 54 +-- lib/model/weather_repo.dart | 32 +- pubspec.yaml | 18 +- 17 files changed, 564 insertions(+), 606 deletions(-) diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index 7e29746..488593e 100644 --- a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -1,7 +1,9 @@ package io.flutter.plugins; import io.flutter.plugin.common.PluginRegistry; -import io.intheloup.geolocation.GeolocationPlugin; +import com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin; +import com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin; +import com.baseflow.permissionhandler.PermissionHandlerPlugin; /** * Generated file. Do not edit. @@ -11,7 +13,9 @@ public static void registerWith(PluginRegistry registry) { if (alreadyRegisteredWith(registry)) { return; } - GeolocationPlugin.registerWith(registry.registrarFor("io.intheloup.geolocation.GeolocationPlugin")); + GeolocatorPlugin.registerWith(registry.registrarFor("com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin")); + GoogleApiAvailabilityPlugin.registerWith(registry.registrarFor("com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin")); + PermissionHandlerPlugin.registerWith(registry.registrarFor("com.baseflow.permissionhandler.PermissionHandlerPlugin")); } private static boolean alreadyRegisteredWith(PluginRegistry registry) { diff --git a/android/gradlew b/android/gradlew index 9d82f78..e834973 100644 --- a/android/gradlew +++ b/android/gradlew @@ -1,160 +1,160 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/local.properties b/android/local.properties index 163442f..a00662a 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,3 +1,3 @@ -sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\sdk -flutter.sdk=C:\\flutter +sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\sdk +flutter.sdk=C:\\flutter flutter.buildMode=debug \ No newline at end of file diff --git a/ios/Flutter/Generated.xcconfig b/ios/Flutter/Generated.xcconfig index bd68c00..71c2b9d 100644 --- a/ios/Flutter/Generated.xcconfig +++ b/ios/Flutter/Generated.xcconfig @@ -1,8 +1,7 @@ // This is a generated file; do not edit or check into version control. FLUTTER_ROOT=C:\flutter -FLUTTER_APPLICATION_PATH=c:\Projects\dart\weather +FLUTTER_APPLICATION_PATH=C:\Projects\dart\Weather_Tutorial FLUTTER_TARGET=lib/main.dart -FLUTTER_BUILD_MODE=debug FLUTTER_BUILD_DIR=build SYMROOT=${SOURCE_ROOT}/../build\ios FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m index f1cc452..bd43789 100644 --- a/ios/Runner/GeneratedPluginRegistrant.m +++ b/ios/Runner/GeneratedPluginRegistrant.m @@ -3,12 +3,16 @@ // #import "GeneratedPluginRegistrant.h" -#import +#import +#import +#import @implementation GeneratedPluginRegistrant + (void)registerWithRegistry:(NSObject*)registry { - [GeolocationPlugin registerWithRegistrar:[registry registrarForPlugin:@"GeolocationPlugin"]]; + [GeolocatorPlugin registerWithRegistrar:[registry registrarForPlugin:@"GeolocatorPlugin"]]; + [GoogleApiAvailabilityPlugin registerWithRegistrar:[registry registrarForPlugin:@"GoogleApiAvailabilityPlugin"]]; + [PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]]; } @end diff --git a/lib/const.dart b/lib/const.dart index b6e19dc..1a61603 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -1 +1 @@ -const API_KEY = '[Your API KEY]'; +const API_KEY = '[OPEN WEATHER API KEY]'; diff --git a/lib/json/response.g.dart b/lib/json/response.g.dart index fa4b331..14a3ae7 100644 --- a/lib/json/response.g.dart +++ b/lib/json/response.g.dart @@ -1,156 +1,156 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'response.dart'; - -// ************************************************************************** -// Generator: JsonSerializableGenerator -// ************************************************************************** - -BaseResponse _$BaseResponseFromJson(Map json) => - new BaseResponse( - json['message'] as String, - json['cod'] as String, - json['count'] as int, - (json['list'] as List) - ?.map((e) => - e == null ? null : new City.fromJson(e as Map)) - ?.toList()); - -abstract class _$BaseResponseSerializerMixin { - String get message; - String get cod; - int get count; - List get cities; - Map toJson() => { - 'message': message, - 'cod': cod, - 'count': count, - 'list': cities - }; -} - -City _$CityFromJson(Map json) => new City( - json['id'] as int, - json['name'] as String, - json['coord'] == null - ? null - : new Coord.fromJson(json['coord'] as Map), - json['main'] == null - ? null - : new Main.fromJson(json['main'] as Map), - json['dt'] as int, - json['wind'] == null - ? null - : new Wind.fromJson(json['wind'] as Map), - json['rain'] == null - ? null - : new Rain.fromJson(json['rain'] as Map), - json['clouds'] == null - ? null - : new Clouds.fromJson(json['clouds'] as Map), - (json['weather'] as List) - ?.map((e) => - e == null ? null : new Weather.fromJson(e as Map)) - ?.toList()); - -abstract class _$CitySerializerMixin { - int get id; - String get name; - Coord get coord; - Main get main; - int get dt; - Wind get wind; - Rain get rain; - Clouds get clouds; - List get weather; - Map toJson() => { - 'id': id, - 'name': name, - 'coord': coord, - 'main': main, - 'dt': dt, - 'wind': wind, - 'rain': rain, - 'clouds': clouds, - 'weather': weather - }; -} - -Coord _$CoordFromJson(Map json) => new Coord( - (json['lat'] as num)?.toDouble(), (json['lon'] as num)?.toDouble()); - -abstract class _$CoordSerializerMixin { - double get lat; - double get lon; - Map toJson() => {'lat': lat, 'lon': lon}; -} - -Main _$MainFromJson(Map json) => new Main( - (json['temp'] as num)?.toDouble(), - (json['pressure'] as num)?.toDouble(), - json['humidity'] as int, - (json['temp_max'] as num)?.toDouble(), - (json['temp_min'] as num)?.toDouble()); - -abstract class _$MainSerializerMixin { - double get temp; - double get pressure; - int get humidity; - double get tempMax; - double get tempMin; - Map toJson() => { - 'temp': temp, - 'pressure': pressure, - 'humidity': humidity, - 'temp_max': tempMax, - 'temp_min': tempMin - }; -} - -Wind _$WindFromJson(Map json) => new Wind( - (json['speed'] as num)?.toDouble(), - (json['deg'] as num)?.toDouble(), - (json['gust'] as num)?.toDouble()); - -abstract class _$WindSerializerMixin { - double get speed; - double get deg; - double get gust; - Map toJson() => - {'speed': speed, 'deg': deg, 'gust': gust}; -} - -Rain _$RainFromJson(Map json) => - new Rain((json['3h'] as num)?.toDouble()); - -abstract class _$RainSerializerMixin { - double get threeHour; - Map toJson() => {'3h': threeHour}; -} - -Clouds _$CloudsFromJson(Map json) => - new Clouds(all: json['all'] as int); - -abstract class _$CloudsSerializerMixin { - int get all; - Map toJson() => {'all': all}; -} - -Weather _$WeatherFromJson(Map json) => new Weather( - id: json['id'] as int, - main: json['main'] as String, - description: json['description'] as String, - icon: json['icon'] as String); - -abstract class _$WeatherSerializerMixin { - int get id; - String get main; - String get description; - String get icon; - Map toJson() => { - 'id': id, - 'main': main, - 'description': description, - 'icon': icon - }; -} +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'response.dart'; + +// ************************************************************************** +// Generator: JsonSerializableGenerator +// ************************************************************************** + +BaseResponse _$BaseResponseFromJson(Map json) => + new BaseResponse( + json['message'] as String, + json['cod'] as String, + json['count'] as int, + (json['list'] as List) + ?.map((e) => + e == null ? null : new City.fromJson(e as Map)) + ?.toList()); + +abstract class _$BaseResponseSerializerMixin { + String get message; + String get cod; + int get count; + List get cities; + Map toJson() => { + 'message': message, + 'cod': cod, + 'count': count, + 'list': cities + }; +} + +City _$CityFromJson(Map json) => new City( + json['id'] as int, + json['name'] as String, + json['coord'] == null + ? null + : new Coord.fromJson(json['coord'] as Map), + json['main'] == null + ? null + : new Main.fromJson(json['main'] as Map), + json['dt'] as int, + json['wind'] == null + ? null + : new Wind.fromJson(json['wind'] as Map), + json['rain'] == null + ? null + : new Rain.fromJson(json['rain'] as Map), + json['clouds'] == null + ? null + : new Clouds.fromJson(json['clouds'] as Map), + (json['weather'] as List) + ?.map((e) => + e == null ? null : new Weather.fromJson(e as Map)) + ?.toList()); + +abstract class _$CitySerializerMixin { + int get id; + String get name; + Coord get coord; + Main get main; + int get dt; + Wind get wind; + Rain get rain; + Clouds get clouds; + List get weather; + Map toJson() => { + 'id': id, + 'name': name, + 'coord': coord, + 'main': main, + 'dt': dt, + 'wind': wind, + 'rain': rain, + 'clouds': clouds, + 'weather': weather + }; +} + +Coord _$CoordFromJson(Map json) => new Coord( + (json['lat'] as num)?.toDouble(), (json['lon'] as num)?.toDouble()); + +abstract class _$CoordSerializerMixin { + double get lat; + double get lon; + Map toJson() => {'lat': lat, 'lon': lon}; +} + +Main _$MainFromJson(Map json) => new Main( + (json['temp'] as num)?.toDouble(), + (json['pressure'] as num)?.toDouble(), + json['humidity'] as int, + (json['temp_max'] as num)?.toDouble(), + (json['temp_min'] as num)?.toDouble()); + +abstract class _$MainSerializerMixin { + double get temp; + double get pressure; + int get humidity; + double get tempMax; + double get tempMin; + Map toJson() => { + 'temp': temp, + 'pressure': pressure, + 'humidity': humidity, + 'temp_max': tempMax, + 'temp_min': tempMin + }; +} + +Wind _$WindFromJson(Map json) => new Wind( + (json['speed'] as num)?.toDouble(), + (json['deg'] as num)?.toDouble(), + (json['gust'] as num)?.toDouble()); + +abstract class _$WindSerializerMixin { + double get speed; + double get deg; + double get gust; + Map toJson() => + {'speed': speed, 'deg': deg, 'gust': gust}; +} + +Rain _$RainFromJson(Map json) => + new Rain((json['3h'] as num)?.toDouble()); + +abstract class _$RainSerializerMixin { + double get threeHour; + Map toJson() => {'3h': threeHour}; +} + +Clouds _$CloudsFromJson(Map json) => + new Clouds(all: json['all'] as int); + +abstract class _$CloudsSerializerMixin { + int get all; + Map toJson() => {'all': all}; +} + +Weather _$WeatherFromJson(Map json) => new Weather( + id: json['id'] as int, + main: json['main'] as String, + description: json['description'] as String, + icon: json['icon'] as String); + +abstract class _$WeatherSerializerMixin { + int get id; + String get main; + String get description; + String get icon; + Map toJson() => { + 'id': id, + 'main': main, + 'description': description, + 'icon': icon + }; +} diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index 6758b8f..7095d1e 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,15 +1,15 @@ -{ - "@@last_modified": "2018-04-27T17:16:00.180810", - "title": "Weather Application", - "@title": { - "description": "Title for the Weather Application", - "type": "text", - "placeholders": {} - }, - "button": "Get the Weather", - "@button": { - "description": "get weather button", - "type": "text", - "placeholders": {} - } +{ + "@@last_modified": "2018-04-27T17:16:00.180810", + "title": "Weather Application", + "@title": { + "description": "Title for the Weather Application", + "type": "text", + "placeholders": {} + }, + "button": "Get the Weather", + "@button": { + "description": "get weather button", + "type": "text", + "placeholders": {} + } } \ No newline at end of file diff --git a/lib/l10n/messages_all.dart b/lib/l10n/messages_all.dart index ec21e4c..16eac54 100644 --- a/lib/l10n/messages_all.dart +++ b/lib/l10n/messages_all.dart @@ -1,69 +1,69 @@ -// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart -// This is a library that looks up messages for specific locales by -// delegating to the appropriate library. - -import 'dart:async'; - -import 'package:intl/intl.dart'; -import 'package:intl/message_lookup_by_library.dart'; -// ignore: implementation_imports -import 'package:intl/src/intl_helpers.dart'; - -import 'messages_es.dart' as messages_es; -import 'messages_en.dart' as messages_en; -import 'messages_messages.dart' as messages_messages; -import 'messages_ja.dart' as messages_ja; - -typedef Future LibraryLoader(); -Map _deferredLibraries = { - 'es': () => new Future.value(null), - 'en': () => new Future.value(null), - 'messages': () => new Future.value(null), - 'ja': () => new Future.value(null), -}; - -MessageLookupByLibrary _findExact(localeName) { - switch (localeName) { - case 'es': - return messages_es.messages; - case 'en': - return messages_en.messages; - case 'messages': - return messages_messages.messages; - case 'ja': - return messages_ja.messages; - default: - return null; - } -} - -/// User programs should call this before using [localeName] for messages. -Future initializeMessages(String localeName) async { - var availableLocale = Intl.verifiedLocale( - localeName, - (locale) => _deferredLibraries[locale] != null, - onFailure: (_) => null); - if (availableLocale == null) { - return new Future.value(false); - } - var lib = _deferredLibraries[availableLocale]; - await (lib == null ? new Future.value(false) : lib()); - initializeInternalMessageLookup(() => new CompositeMessageLookup()); - messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); - return new Future.value(true); -} - -bool _messagesExistFor(String locale) { - try { - return _findExact(locale) != null; - } catch (e) { - return false; - } -} - -MessageLookupByLibrary _findGeneratedMessagesFor(locale) { - var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, - onFailure: (_) => null); - if (actualLocale == null) return null; - return _findExact(actualLocale); -} +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that looks up messages for specific locales by +// delegating to the appropriate library. + +import 'dart:async'; + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; +// ignore: implementation_imports +import 'package:intl/src/intl_helpers.dart'; + +import 'messages_es.dart' as messages_es; +import 'messages_en.dart' as messages_en; +import 'messages_messages.dart' as messages_messages; +import 'messages_ja.dart' as messages_ja; + +typedef Future LibraryLoader(); +Map _deferredLibraries = { + 'es': () => new Future.value(null), + 'en': () => new Future.value(null), + 'messages': () => new Future.value(null), + 'ja': () => new Future.value(null), +}; + +MessageLookupByLibrary _findExact(localeName) { + switch (localeName) { + case 'es': + return messages_es.messages; + case 'en': + return messages_en.messages; + case 'messages': + return messages_messages.messages; + case 'ja': + return messages_ja.messages; + default: + return null; + } +} + +/// User programs should call this before using [localeName] for messages. +Future initializeMessages(String localeName) async { + var availableLocale = Intl.verifiedLocale( + localeName, + (locale) => _deferredLibraries[locale] != null, + onFailure: (_) => null); + if (availableLocale == null) { + return new Future.value(false); + } + var lib = _deferredLibraries[availableLocale]; + await (lib == null ? new Future.value(false) : lib()); + initializeInternalMessageLookup(() => new CompositeMessageLookup()); + messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor); + return new Future.value(true); +} + +bool _messagesExistFor(String locale) { + try { + return _findExact(locale) != null; + } catch (e) { + return false; + } +} + +MessageLookupByLibrary _findGeneratedMessagesFor(locale) { + var actualLocale = Intl.verifiedLocale(locale, _messagesExistFor, + onFailure: (_) => null); + if (actualLocale == null) return null; + return _findExact(actualLocale); +} diff --git a/lib/l10n/messages_en.dart b/lib/l10n/messages_en.dart index f2e37c3..52e03f1 100644 --- a/lib/l10n/messages_en.dart +++ b/lib/l10n/messages_en.dart @@ -1,25 +1,25 @@ -// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart -// This is a library that provides messages for a en locale. All the -// messages from the main program should be duplicated here with the same -// function name. - -import 'package:intl/intl.dart'; -import 'package:intl/message_lookup_by_library.dart'; - -final messages = new MessageLookup(); - -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); - -class MessageLookup extends MessageLookupByLibrary { - get localeName => 'en'; - - final messages = _notInlinedMessages(_notInlinedMessages); - static _notInlinedMessages(_) => { - "title": MessageLookupByLibrary.simpleMessage("Weather Application"), - "button": MessageLookupByLibrary.simpleMessage("Get the Weather") - }; -} +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a en locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +// ignore: unused_element +final _keepAnalysisHappy = Intl.defaultLocale; + +// ignore: non_constant_identifier_names +typedef MessageIfAbsent(String message_str, List args); + +class MessageLookup extends MessageLookupByLibrary { + get localeName => 'en'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title": MessageLookupByLibrary.simpleMessage("Weather Application"), + "button": MessageLookupByLibrary.simpleMessage("Get the Weather") + }; +} diff --git a/lib/l10n/messages_es.dart b/lib/l10n/messages_es.dart index 69404c1..0810db9 100644 --- a/lib/l10n/messages_es.dart +++ b/lib/l10n/messages_es.dart @@ -1,26 +1,26 @@ -// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart -// This is a library that provides messages for a es locale. All the -// messages from the main program should be duplicated here with the same -// function name. - -import 'package:intl/intl.dart'; -import 'package:intl/message_lookup_by_library.dart'; - -final messages = new MessageLookup(); - -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); - -class MessageLookup extends MessageLookupByLibrary { - get localeName => 'es'; - - final messages = _notInlinedMessages(_notInlinedMessages); - static _notInlinedMessages(_) => { - "title": - MessageLookupByLibrary.simpleMessage("Aplicación Meteorológica"), - "button": MessageLookupByLibrary.simpleMessage("Obtener el Clima") - }; -} +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a es locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +// ignore: unused_element +final _keepAnalysisHappy = Intl.defaultLocale; + +// ignore: non_constant_identifier_names +typedef MessageIfAbsent(String message_str, List args); + +class MessageLookup extends MessageLookupByLibrary { + get localeName => 'es'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title": + MessageLookupByLibrary.simpleMessage("Aplicación Meteorológica"), + "button": MessageLookupByLibrary.simpleMessage("Obtener el Clima") + }; +} diff --git a/lib/l10n/messages_ja.dart b/lib/l10n/messages_ja.dart index 9f2a089..f976165 100644 --- a/lib/l10n/messages_ja.dart +++ b/lib/l10n/messages_ja.dart @@ -1,25 +1,25 @@ -// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart -// This is a library that provides messages for a ja locale. All the -// messages from the main program should be duplicated here with the same -// function name. - -import 'package:intl/intl.dart'; -import 'package:intl/message_lookup_by_library.dart'; - -final messages = new MessageLookup(); - -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); - -class MessageLookup extends MessageLookupByLibrary { - get localeName => 'ja'; - - final messages = _notInlinedMessages(_notInlinedMessages); - static _notInlinedMessages(_) => { - "title": MessageLookupByLibrary.simpleMessage("天気アプリケーション"), - "button": MessageLookupByLibrary.simpleMessage("天気を取る") - }; -} +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a ja locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +// ignore: unused_element +final _keepAnalysisHappy = Intl.defaultLocale; + +// ignore: non_constant_identifier_names +typedef MessageIfAbsent(String message_str, List args); + +class MessageLookup extends MessageLookupByLibrary { + get localeName => 'ja'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title": MessageLookupByLibrary.simpleMessage("天気アプリケーション"), + "button": MessageLookupByLibrary.simpleMessage("天気を取る") + }; +} diff --git a/lib/l10n/messages_messages.dart b/lib/l10n/messages_messages.dart index 5c425a7..afa05a2 100644 --- a/lib/l10n/messages_messages.dart +++ b/lib/l10n/messages_messages.dart @@ -1,25 +1,25 @@ -// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart -// This is a library that provides messages for a messages locale. All the -// messages from the main program should be duplicated here with the same -// function name. - -import 'package:intl/intl.dart'; -import 'package:intl/message_lookup_by_library.dart'; - -final messages = new MessageLookup(); - -// ignore: unused_element -final _keepAnalysisHappy = Intl.defaultLocale; - -// ignore: non_constant_identifier_names -typedef MessageIfAbsent(String message_str, List args); - -class MessageLookup extends MessageLookupByLibrary { - get localeName => 'messages'; - - final messages = _notInlinedMessages(_notInlinedMessages); - static _notInlinedMessages(_) => { - "title": MessageLookupByLibrary.simpleMessage("Weather Application"), - "button": MessageLookupByLibrary.simpleMessage("Get the Weather") - }; -} +// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart +// This is a library that provides messages for a messages locale. All the +// messages from the main program should be duplicated here with the same +// function name. + +import 'package:intl/intl.dart'; +import 'package:intl/message_lookup_by_library.dart'; + +final messages = new MessageLookup(); + +// ignore: unused_element +final _keepAnalysisHappy = Intl.defaultLocale; + +// ignore: non_constant_identifier_names +typedef MessageIfAbsent(String message_str, List args); + +class MessageLookup extends MessageLookupByLibrary { + get localeName => 'messages'; + + final messages = _notInlinedMessages(_notInlinedMessages); + static _notInlinedMessages(_) => { + "title": MessageLookupByLibrary.simpleMessage("Weather Application"), + "button": MessageLookupByLibrary.simpleMessage("Get the Weather") + }; +} diff --git a/lib/main.dart b/lib/main.dart index cb00d2f..cdebdcc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,9 +7,6 @@ import 'package:weather/model/model.dart'; import 'package:weather/model/model_provider.dart'; import 'package:weather/localization/localizations.dart'; -//unimport if you need the initState function stuff. - -import 'package:geolocation/geolocation.dart'; import 'package:rx_widgets/rx_widgets.dart'; @@ -48,30 +45,12 @@ class MyApp extends StatelessWidget { } } -class MyHomePage extends StatefulWidget { - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - @override - void initState() { - super.initState(); - - // If Geolocation is unable to get location in emulator, uncomment this and then restart the program. - // This tends to fix the error and you can see if the GPS is actually getting the location. - var x = Geolocation.locationUpdates( - accuracy: LocationAccuracy.best, inBackground: false); - x.listen((d) => print(d.isSuccessful)); - } - +class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { Locale myLocale = Localizations.localeOf(context); - //call to getGpsCommand handler on build. If GPS is active comes back with true, else false. - ModelProvider - .of(context) + ModelProvider.of(context) .changeLocaleCommand .call(myLocale.languageCode.toString()); ModelProvider.of(context).getGpsCommand.call(); @@ -92,11 +71,10 @@ class _MyHomePageState extends State { child: Center( child: RxLoader( radius: 20.0, - commandResults: ModelProvider.of(context).getGpsCommand, + commandResults: ModelProvider.of(context).getGpsCommand.results, dataBuilder: (context, data) => Row( children: [ Text(data ? "GPS is Active" : "GPS is Inactive"), - // Added logic to change the Icon when GPS is inactive. IconButton( icon: Icon( data ? Icons.gps_fixed : Icons.gps_not_fixed), @@ -134,7 +112,8 @@ class _MyHomePageState extends State { Expanded( child: RxLoader>( radius: 30.0, - commandResults: ModelProvider.of(context).updateWeatherCommand, + commandResults: + ModelProvider.of(context).updateWeatherCommand.results, dataBuilder: (context, data) => WeatherList(data), placeHolderBuilder: (context) => Center(child: Text("No Data")), errorBuilder: (context, exception) => @@ -145,19 +124,16 @@ class _MyHomePageState extends State { padding: EdgeInsets.all(10.0), child: Row( children: [ - //changed to expanded for more consistency. Expanded( child: WidgetSelector( - buildEvents: ModelProvider - .of(context) + buildEvents: ModelProvider.of(context) .updateWeatherCommand .canExecute, onTrue: MaterialButton( elevation: 5.0, color: Colors.blueGrey, child: Text(AppLocalizations.of(context).button), - onPressed: ModelProvider - .of(context) + onPressed: ModelProvider.of(context) .updateLocationStreamCommand .call, ), @@ -169,7 +145,6 @@ class _MyHomePageState extends State { ), ), ), - //changed to expanded for more consistency. Expanded( child: Column( children: [ @@ -211,7 +186,7 @@ class WeatherList extends StatelessWidget { ), subtitle: Container( padding: EdgeInsets.all(10.0), - child: Text(list[index].temperature.toStringAsFixed(2)), + child: Text("${list[index].temperature.toStringAsFixed(2)}° F"), ), trailing: Container( child: Column( diff --git a/lib/model/model_command.dart b/lib/model/model_command.dart index a2b43e0..1884276 100644 --- a/lib/model/model_command.dart +++ b/lib/model/model_command.dart @@ -1,5 +1,5 @@ import 'package:rx_command/rx_command.dart'; -import 'package:geolocation/geolocation.dart'; +import 'package:geolocator/geolocator.dart'; import 'package:rxdart/rxdart.dart'; // import 'package:rxdart/streams.dart'; @@ -9,17 +9,15 @@ import 'package:weather/model/weather_repo.dart'; class ModelCommand { final WeatherRepo weatherRepo; - // final RxCommand updateLocationCommand; - final RxCommand> updateWeatherCommand; - final RxCommand getGpsCommand; + final RxCommand> updateWeatherCommand; + final RxCommand getGpsCommand; final RxCommand radioCheckedCommand; - final RxCommand addCitiesCommand; - final RxCommand changeLocaleCommand; - final RxCommand updateLocationStreamCommand; + final RxCommand addCitiesCommand; + final RxCommand changeLocaleCommand; + final RxCommand updateLocationStreamCommand; ModelCommand._( this.weatherRepo, - // this.updateLocationCommand, this.updateWeatherCommand, this.getGpsCommand, this.radioCheckedCommand, @@ -29,51 +27,35 @@ class ModelCommand { ); factory ModelCommand(WeatherRepo repo) { - final _getGpsCommand = RxCommand.createAsync2(repo.getGps); + final _getGpsCommand = RxCommand.createAsyncNoParam(repo.getGps); - final _radioCheckedCommand = RxCommand.createSync3((b) => b); + final _radioCheckedCommand = RxCommand.createSync((b) => b); final _changeLocaleCommand = - RxCommand.createSync1(repo.setLanguage); - - //A combined Observable of the GPS and Radio observables using And logic. If one is false then false will be returned. - //This allows us to have a more dynamic set of circumstances for shutting down the buttons. - // final Observable _boolCombine = Observable - // .combineLatest2(_getGpsCommand.results, _radioCheckedCommand.results, - // (gps, radio) => gps && radio) - // .distinctUnique(); + RxCommand.createSyncNoResult(repo.setLanguage); //Two Observables needed because they are only cold observables (single subscription). final _boolCombineA = - CombineObs(_getGpsCommand.results, _radioCheckedCommand.results) - .combinedObservable; + CombineObs(_getGpsCommand, _radioCheckedCommand).combinedObservable; final _boolCombineB = - CombineObs(_getGpsCommand.results, _radioCheckedCommand.results) - .combinedObservable; - - // final _updateLocationCommand = - // RxCommand.createAsync2(repo.updateLocation); + CombineObs(_getGpsCommand, _radioCheckedCommand).combinedObservable; - final _updateWeatherCommand = RxCommand - .createAsync3>(repo.updateWeather, + final _updateWeatherCommand = + RxCommand.createAsync>(repo.updateWeather, canExecute: _boolCombineA); - final _addCitiesCommand = RxCommand.createSync1(repo.addCities); + final _addCitiesCommand = RxCommand.createSyncNoResult(repo.addCities); - final _updateLocationStreamCommand = RxCommand - .createFromStream(repo.updateLocationStream, + final _updateLocationStreamCommand = + RxCommand.createAsync(repo.updateLocation, canExecute: _boolCombineB); - // _updateLocationCommand.results.listen(_updateWeatherCommand); - //using a stream based command now because lastKnownLocation is not as consistent as [currentLocation] - _updateLocationStreamCommand.results - .listen((data) => _updateWeatherCommand(data)); + _updateLocationStreamCommand.listen((data) => _updateWeatherCommand(data)); - _updateWeatherCommand(null); + // _updateWeatherCommand(null); return ModelCommand._( repo, - // _updateLocationCommand, _updateWeatherCommand, _getGpsCommand, _radioCheckedCommand, diff --git a/lib/model/weather_repo.dart b/lib/model/weather_repo.dart index 0c30fc6..d645691 100644 --- a/lib/model/weather_repo.dart +++ b/lib/model/weather_repo.dart @@ -3,8 +3,7 @@ import 'dart:convert'; import 'package:http/http.dart' as http; -import 'package:geolocation/geolocation.dart'; - +import 'package:geolocator/geolocator.dart'; import 'package:weather/json/response.dart'; import 'package:weather/model/model.dart'; @@ -26,19 +25,20 @@ class WeatherRepo { lang = code; } - Future> updateWeather(LocationResult result) async { + Future> updateWeather(Position result) async { String url; if (result != null) { url = - 'http://api.openweathermap.org/data/2.5/find?lat=${result.location.latitude}&lon=${result.location.longitude}&cnt=$cnt&appid=$API_KEY&lang=$lang'; + 'http://api.openweathermap.org/data/2.5/find?lat=${result.latitude}&lon=${result.longitude}&cnt=$cnt&appid=$API_KEY&lang=$lang'; } else { url = 'http://api.openweathermap.org/data/2.5/find?lat=43&lon=-79&cnt=10&appid=$API_KEY'; } + final response = await client.get(url); - List req = BaseResponse - .fromJson(json.decode(response.body) as Map) + List req = BaseResponse.fromJson( + json.decode(response.body) as Map) .cities .map((city) => WeatherModel.fromResponse(city)) .toList(); @@ -46,23 +46,15 @@ class WeatherRepo { return req; } - // Future updateLocation() async { - // Future result = Geolocation.lastKnownLocation(); - // return result; - // } - - //uses Stream instead of future. Mainly done because lastKnownLocation isn't as reliable as locationUpdates. - //when geolocation plugin is fixed or better plugin is released, will update code. - - Stream updateLocationStream(dynamic item) { - Stream stream = Geolocation.currentLocation( - accuracy: LocationAccuracy.best, inBackground: false); - return stream; + Future updateLocation(dynamic item) { + Future location = Geolocator().getCurrentPosition(); + return location; } Future getGps() async { - final GeolocationResult result = await Geolocation.isLocationOperational(); - if (result.isSuccessful) + final GeolocationStatus result = + await Geolocator().checkGeolocationPermissionStatus(); + if (result == GeolocationStatus.granted) return true; else return false; diff --git a/pubspec.yaml b/pubspec.yaml index 63931f9..2f81ef8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,19 +13,21 @@ dependencies: cupertino_icons: ^0.1.0 - json_annotation: ^0.2.3 - rx_command: "^1.0.7" - rx_widgets: "^1.0.2" - geolocation: "^0.2.1" - rxdart: "^0.16.6" + json_annotation: ^2.0.0 + rx_command: ^4.1.1 + rx_widgets: ^2.2.0 + geolocator: ^2.1.1 + # geolocation: "^0.2.1" + rxdart: ^0.20.0 + dev_dependencies: - build_runner: ^0.8.0 - json_serializable: ^0.5.0 - intl_translation: "^0.16.6" + build_runner: ^1.2.1 + json_serializable: ^2.0.1 + intl_translation: ^0.17.2 flutter_test: From b6a89aebbe573788ad727463d7e7349ace55da07 Mon Sep 17 00:00:00 2001 From: Tensor-Programming Date: Tue, 7 May 2019 06:12:03 -0400 Subject: [PATCH 2/5] updated json and for androidx --- android/android.iml | 19 ++ android/app/app.iml | 155 ++++++++++ android/app/build.gradle | 10 +- .../plugins/GeneratedPluginRegistrant.java | 4 +- android/build.gradle | 2 +- android/gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.properties | 4 +- android/local.properties | 8 +- ios/Flutter/Generated.xcconfig | 2 + ios/Runner/GeneratedPluginRegistrant.m | 4 +- lib/const.dart | 2 +- lib/json/response.dart | 19 +- lib/json/response.g.dart | 285 ++++++++---------- lib/main.dart | 11 +- lib/model/model_command.dart | 14 +- lib/model/weather_repo.dart | 10 +- pubspec.yaml | 23 +- 17 files changed, 368 insertions(+), 206 deletions(-) create mode 100644 android/android.iml create mode 100644 android/app/app.iml diff --git a/android/android.iml b/android/android.iml new file mode 100644 index 0000000..096e667 --- /dev/null +++ b/android/android.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/app.iml b/android/app/app.iml new file mode 100644 index 0000000..a596c67 --- /dev/null +++ b/android/app/app.iml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 22a4d07..25fa1e9 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -15,7 +15,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' @@ -25,10 +25,10 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.weather" minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -46,6 +46,6 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + androidTestImplementation 'androidx.test:runner:1.1.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' } diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index 488593e..39cea5a 100644 --- a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -3,7 +3,7 @@ import io.flutter.plugin.common.PluginRegistry; import com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin; import com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin; -import com.baseflow.permissionhandler.PermissionHandlerPlugin; +import com.baseflow.location_permissions.LocationPermissionsPlugin; /** * Generated file. Do not edit. @@ -15,7 +15,7 @@ public static void registerWith(PluginRegistry registry) { } GeolocatorPlugin.registerWith(registry.registrarFor("com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin")); GoogleApiAvailabilityPlugin.registerWith(registry.registrarFor("com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin")); - PermissionHandlerPlugin.registerWith(registry.registrarFor("com.baseflow.permissionhandler.PermissionHandlerPlugin")); + LocationPermissionsPlugin.registerWith(registry.registrarFor("com.baseflow.location_permissions.LocationPermissionsPlugin")); } private static boolean alreadyRegisteredWith(PluginRegistry registry) { diff --git a/android/build.gradle b/android/build.gradle index b2483d3..8ada0cd 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.4.0' } } diff --git a/android/gradle.properties b/android/gradle.properties index b472197..76cfc20 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1 +1,3 @@ org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 651b997..0884226 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Tue May 07 05:57:35 EDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/android/local.properties b/android/local.properties index a00662a..7cc1df3 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,3 +1,5 @@ -sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\sdk -flutter.sdk=C:\\flutter -flutter.buildMode=debug \ No newline at end of file +sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\sdk +flutter.sdk=C:\\flutter +flutter.buildMode=debug +flutter.versionName=1.0.0 +flutter.versionCode=1 \ No newline at end of file diff --git a/ios/Flutter/Generated.xcconfig b/ios/Flutter/Generated.xcconfig index 71c2b9d..d5e657b 100644 --- a/ios/Flutter/Generated.xcconfig +++ b/ios/Flutter/Generated.xcconfig @@ -5,3 +5,5 @@ FLUTTER_TARGET=lib/main.dart FLUTTER_BUILD_DIR=build SYMROOT=${SOURCE_ROOT}/../build\ios FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios +FLUTTER_BUILD_NAME=1.0.0 +FLUTTER_BUILD_NUMBER=1 diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m index bd43789..afb0da8 100644 --- a/ios/Runner/GeneratedPluginRegistrant.m +++ b/ios/Runner/GeneratedPluginRegistrant.m @@ -5,14 +5,14 @@ #import "GeneratedPluginRegistrant.h" #import #import -#import +#import @implementation GeneratedPluginRegistrant + (void)registerWithRegistry:(NSObject*)registry { [GeolocatorPlugin registerWithRegistrar:[registry registrarForPlugin:@"GeolocatorPlugin"]]; [GoogleApiAvailabilityPlugin registerWithRegistrar:[registry registrarForPlugin:@"GoogleApiAvailabilityPlugin"]]; - [PermissionHandlerPlugin registerWithRegistrar:[registry registrarForPlugin:@"PermissionHandlerPlugin"]]; + [LocationPermissionsPlugin registerWithRegistrar:[registry registrarForPlugin:@"LocationPermissionsPlugin"]]; } @end diff --git a/lib/const.dart b/lib/const.dart index 1a61603..b6e19dc 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -1 +1 @@ -const API_KEY = '[OPEN WEATHER API KEY]'; +const API_KEY = '[Your API KEY]'; diff --git a/lib/json/response.dart b/lib/json/response.dart index b35d6e5..28a75e0 100644 --- a/lib/json/response.dart +++ b/lib/json/response.dart @@ -3,7 +3,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'response.g.dart'; @JsonSerializable() -class BaseResponse extends Object with _$BaseResponseSerializerMixin { +class BaseResponse { final String message; final String cod; final int count; @@ -20,10 +20,12 @@ class BaseResponse extends Object with _$BaseResponseSerializerMixin { factory BaseResponse.fromJson(Map json) => _$BaseResponseFromJson(json); + + Map toJson() => _$BaseResponseToJson(this); } @JsonSerializable() -class City extends Object with _$CitySerializerMixin { +class City { final int id; final String name; final Coord coord; @@ -49,10 +51,11 @@ class City extends Object with _$CitySerializerMixin { this.weather, ); factory City.fromJson(Map json) => _$CityFromJson(json); + Map toJson() => _$CityToJson(this); } @JsonSerializable() -class Coord extends Object with _$CoordSerializerMixin { +class Coord { final double lat; final double lon; Coord(this.lat, this.lon); @@ -61,7 +64,7 @@ class Coord extends Object with _$CoordSerializerMixin { } @JsonSerializable() -class Main extends Object with _$MainSerializerMixin { +class Main { final double temp; final double pressure; final int humidity; @@ -83,7 +86,7 @@ class Main extends Object with _$MainSerializerMixin { } @JsonSerializable() -class Wind extends Object with _$WindSerializerMixin { +class Wind { final double speed; final double deg; @@ -99,7 +102,7 @@ class Wind extends Object with _$WindSerializerMixin { } @JsonSerializable() -class Rain extends Object with _$RainSerializerMixin { +class Rain { @JsonKey(name: "3h") final double threeHour; Rain(this.threeHour); @@ -108,7 +111,7 @@ class Rain extends Object with _$RainSerializerMixin { } @JsonSerializable() -class Clouds extends Object with _$CloudsSerializerMixin { +class Clouds { Clouds({this.all}); final int all; @@ -116,7 +119,7 @@ class Clouds extends Object with _$CloudsSerializerMixin { } @JsonSerializable() -class Weather extends Object with _$WeatherSerializerMixin { +class Weather { Weather({ this.id, this.main, diff --git a/lib/json/response.g.dart b/lib/json/response.g.dart index 14a3ae7..614e033 100644 --- a/lib/json/response.g.dart +++ b/lib/json/response.g.dart @@ -1,156 +1,129 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'response.dart'; - -// ************************************************************************** -// Generator: JsonSerializableGenerator -// ************************************************************************** - -BaseResponse _$BaseResponseFromJson(Map json) => - new BaseResponse( - json['message'] as String, - json['cod'] as String, - json['count'] as int, - (json['list'] as List) - ?.map((e) => - e == null ? null : new City.fromJson(e as Map)) - ?.toList()); - -abstract class _$BaseResponseSerializerMixin { - String get message; - String get cod; - int get count; - List get cities; - Map toJson() => { - 'message': message, - 'cod': cod, - 'count': count, - 'list': cities - }; -} - -City _$CityFromJson(Map json) => new City( - json['id'] as int, - json['name'] as String, - json['coord'] == null - ? null - : new Coord.fromJson(json['coord'] as Map), - json['main'] == null - ? null - : new Main.fromJson(json['main'] as Map), - json['dt'] as int, - json['wind'] == null - ? null - : new Wind.fromJson(json['wind'] as Map), - json['rain'] == null - ? null - : new Rain.fromJson(json['rain'] as Map), - json['clouds'] == null - ? null - : new Clouds.fromJson(json['clouds'] as Map), - (json['weather'] as List) - ?.map((e) => - e == null ? null : new Weather.fromJson(e as Map)) - ?.toList()); - -abstract class _$CitySerializerMixin { - int get id; - String get name; - Coord get coord; - Main get main; - int get dt; - Wind get wind; - Rain get rain; - Clouds get clouds; - List get weather; - Map toJson() => { - 'id': id, - 'name': name, - 'coord': coord, - 'main': main, - 'dt': dt, - 'wind': wind, - 'rain': rain, - 'clouds': clouds, - 'weather': weather - }; -} - -Coord _$CoordFromJson(Map json) => new Coord( - (json['lat'] as num)?.toDouble(), (json['lon'] as num)?.toDouble()); - -abstract class _$CoordSerializerMixin { - double get lat; - double get lon; - Map toJson() => {'lat': lat, 'lon': lon}; -} - -Main _$MainFromJson(Map json) => new Main( - (json['temp'] as num)?.toDouble(), - (json['pressure'] as num)?.toDouble(), - json['humidity'] as int, - (json['temp_max'] as num)?.toDouble(), - (json['temp_min'] as num)?.toDouble()); - -abstract class _$MainSerializerMixin { - double get temp; - double get pressure; - int get humidity; - double get tempMax; - double get tempMin; - Map toJson() => { - 'temp': temp, - 'pressure': pressure, - 'humidity': humidity, - 'temp_max': tempMax, - 'temp_min': tempMin - }; -} - -Wind _$WindFromJson(Map json) => new Wind( - (json['speed'] as num)?.toDouble(), - (json['deg'] as num)?.toDouble(), - (json['gust'] as num)?.toDouble()); - -abstract class _$WindSerializerMixin { - double get speed; - double get deg; - double get gust; - Map toJson() => - {'speed': speed, 'deg': deg, 'gust': gust}; -} - -Rain _$RainFromJson(Map json) => - new Rain((json['3h'] as num)?.toDouble()); - -abstract class _$RainSerializerMixin { - double get threeHour; - Map toJson() => {'3h': threeHour}; -} - -Clouds _$CloudsFromJson(Map json) => - new Clouds(all: json['all'] as int); - -abstract class _$CloudsSerializerMixin { - int get all; - Map toJson() => {'all': all}; -} - -Weather _$WeatherFromJson(Map json) => new Weather( - id: json['id'] as int, - main: json['main'] as String, - description: json['description'] as String, - icon: json['icon'] as String); - -abstract class _$WeatherSerializerMixin { - int get id; - String get main; - String get description; - String get icon; - Map toJson() => { - 'id': id, - 'main': main, - 'description': description, - 'icon': icon - }; -} +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'response.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BaseResponse _$BaseResponseFromJson(Map json) { + return BaseResponse( + json['message'] as String, + json['cod'] as String, + json['count'] as int, + (json['list'] as List) + ?.map((e) => + e == null ? null : City.fromJson(e as Map)) + ?.toList()); +} + +Map _$BaseResponseToJson(BaseResponse instance) => + { + 'message': instance.message, + 'cod': instance.cod, + 'count': instance.count, + 'list': instance.cities + }; + +City _$CityFromJson(Map json) { + return City( + json['id'] as int, + json['name'] as String, + json['coord'] == null + ? null + : Coord.fromJson(json['coord'] as Map), + json['main'] == null + ? null + : Main.fromJson(json['main'] as Map), + json['dt'] as int, + json['wind'] == null + ? null + : Wind.fromJson(json['wind'] as Map), + json['rain'] == null + ? null + : Rain.fromJson(json['rain'] as Map), + json['clouds'] == null + ? null + : Clouds.fromJson(json['clouds'] as Map), + (json['weather'] as List) + ?.map((e) => + e == null ? null : Weather.fromJson(e as Map)) + ?.toList()); +} + +Map _$CityToJson(City instance) => { + 'id': instance.id, + 'name': instance.name, + 'coord': instance.coord, + 'main': instance.main, + 'dt': instance.dt, + 'wind': instance.wind, + 'rain': instance.rain, + 'clouds': instance.clouds, + 'weather': instance.weather + }; + +Coord _$CoordFromJson(Map json) { + return Coord( + (json['lat'] as num)?.toDouble(), (json['lon'] as num)?.toDouble()); +} + +Map _$CoordToJson(Coord instance) => + {'lat': instance.lat, 'lon': instance.lon}; + +Main _$MainFromJson(Map json) { + return Main( + (json['temp'] as num)?.toDouble(), + (json['pressure'] as num)?.toDouble(), + json['humidity'] as int, + (json['temp_max'] as num)?.toDouble(), + (json['temp_min'] as num)?.toDouble()); +} + +Map _$MainToJson(Main instance) => { + 'temp': instance.temp, + 'pressure': instance.pressure, + 'humidity': instance.humidity, + 'temp_max': instance.tempMax, + 'temp_min': instance.tempMin + }; + +Wind _$WindFromJson(Map json) { + return Wind((json['speed'] as num)?.toDouble(), + (json['deg'] as num)?.toDouble(), (json['gust'] as num)?.toDouble()); +} + +Map _$WindToJson(Wind instance) => { + 'speed': instance.speed, + 'deg': instance.deg, + 'gust': instance.gust + }; + +Rain _$RainFromJson(Map json) { + return Rain((json['3h'] as num)?.toDouble()); +} + +Map _$RainToJson(Rain instance) => + {'3h': instance.threeHour}; + +Clouds _$CloudsFromJson(Map json) { + return Clouds(all: json['all'] as int); +} + +Map _$CloudsToJson(Clouds instance) => + {'all': instance.all}; + +Weather _$WeatherFromJson(Map json) { + return Weather( + id: json['id'] as int, + main: json['main'] as String, + description: json['description'] as String, + icon: json['icon'] as String); +} + +Map _$WeatherToJson(Weather instance) => { + 'id': instance.id, + 'main': instance.main, + 'description': instance.description, + 'icon': instance.icon + }; diff --git a/lib/main.dart b/lib/main.dart index cdebdcc..676962d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,6 +50,7 @@ class MyHomePage extends StatelessWidget { Widget build(BuildContext context) { Locale myLocale = Localizations.localeOf(context); + //call to getGpsCommand handler on build. If GPS is active comes back with true, else false. ModelProvider.of(context) .changeLocaleCommand .call(myLocale.languageCode.toString()); @@ -75,6 +76,7 @@ class MyHomePage extends StatelessWidget { dataBuilder: (context, data) => Row( children: [ Text(data ? "GPS is Active" : "GPS is Inactive"), + // Added logic to change the Icon when GPS is inactive. IconButton( icon: Icon( data ? Icons.gps_fixed : Icons.gps_not_fixed), @@ -124,6 +126,7 @@ class MyHomePage extends StatelessWidget { padding: EdgeInsets.all(10.0), child: Row( children: [ + //changed to expanded for more consistency. Expanded( child: WidgetSelector( buildEvents: ModelProvider.of(context) @@ -133,9 +136,8 @@ class MyHomePage extends StatelessWidget { elevation: 5.0, color: Colors.blueGrey, child: Text(AppLocalizations.of(context).button), - onPressed: ModelProvider.of(context) - .updateLocationStreamCommand - .call, + onPressed: + ModelProvider.of(context).updateLocationCommand.call, ), onFalse: MaterialButton( elevation: 0.0, @@ -145,6 +147,7 @@ class MyHomePage extends StatelessWidget { ), ), ), + //changed to expanded for more consistency. Expanded( child: Column( children: [ @@ -186,7 +189,7 @@ class WeatherList extends StatelessWidget { ), subtitle: Container( padding: EdgeInsets.all(10.0), - child: Text("${list[index].temperature.toStringAsFixed(2)}° F"), + child: Text(list[index].temperature.toStringAsFixed(2)), ), trailing: Container( child: Column( diff --git a/lib/model/model_command.dart b/lib/model/model_command.dart index 1884276..ef63950 100644 --- a/lib/model/model_command.dart +++ b/lib/model/model_command.dart @@ -14,7 +14,7 @@ class ModelCommand { final RxCommand radioCheckedCommand; final RxCommand addCitiesCommand; final RxCommand changeLocaleCommand; - final RxCommand updateLocationStreamCommand; + final RxCommand updateLocationCommand; ModelCommand._( this.weatherRepo, @@ -22,7 +22,7 @@ class ModelCommand { this.getGpsCommand, this.radioCheckedCommand, this.addCitiesCommand, - this.updateLocationStreamCommand, + this.updateLocationCommand, this.changeLocaleCommand, ); @@ -46,11 +46,11 @@ class ModelCommand { final _addCitiesCommand = RxCommand.createSyncNoResult(repo.addCities); - final _updateLocationStreamCommand = - RxCommand.createAsync(repo.updateLocation, - canExecute: _boolCombineB); + final _updateLocationCommand = RxCommand.createAsync( + repo.updateLocation, + canExecute: _boolCombineB); - _updateLocationStreamCommand.listen((data) => _updateWeatherCommand(data)); + _updateLocationCommand.listen((data) => _updateWeatherCommand(data)); // _updateWeatherCommand(null); @@ -60,7 +60,7 @@ class ModelCommand { _getGpsCommand, _radioCheckedCommand, _addCitiesCommand, - _updateLocationStreamCommand, + _updateLocationCommand, _changeLocaleCommand, ); } diff --git a/lib/model/weather_repo.dart b/lib/model/weather_repo.dart index d645691..f168f2b 100644 --- a/lib/model/weather_repo.dart +++ b/lib/model/weather_repo.dart @@ -3,7 +3,9 @@ import 'dart:convert'; import 'package:http/http.dart' as http; +// import 'package:geolocation/geolocation.dart'; import 'package:geolocator/geolocator.dart'; + import 'package:weather/json/response.dart'; import 'package:weather/model/model.dart'; @@ -34,7 +36,6 @@ class WeatherRepo { url = 'http://api.openweathermap.org/data/2.5/find?lat=43&lon=-79&cnt=10&appid=$API_KEY'; } - final response = await client.get(url); List req = BaseResponse.fromJson( @@ -46,9 +47,10 @@ class WeatherRepo { return req; } - Future updateLocation(dynamic item) { - Future location = Geolocator().getCurrentPosition(); - return location; + Future updateLocation(dynamic data) async { + Future result = + Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best); + return result; } Future getGps() async { diff --git a/pubspec.yaml b/pubspec.yaml index 2f81ef8..cf7e87a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,11 @@ name: weather description: A new Flutter project. +version: 1.0.0+1 + +environment: + sdk: ">=2.2.0 <3.0.0" + dependencies: flutter: sdk: flutter @@ -10,24 +15,20 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.0 + cupertino_icons: ^0.1.2 - json_annotation: ^2.0.0 - rx_command: ^4.1.1 + json_annotation: ^2.2.0 + rx_command: ^4.3.0 rx_widgets: ^2.2.0 - geolocator: ^2.1.1 + geolocator: ^4.0.2 # geolocation: "^0.2.1" rxdart: ^0.20.0 - - - - dev_dependencies: - build_runner: ^1.2.1 - json_serializable: ^2.0.1 - intl_translation: ^0.17.2 + build_runner: ^1.4.0 + json_serializable: ^2.2.2 + intl_translation: ^0.17.4 flutter_test: From de9a9f9f92faae1250ea7545edbdf708ca199e56 Mon Sep 17 00:00:00 2001 From: Tensor-Programming Date: Wed, 17 Jul 2019 13:50:11 -0400 Subject: [PATCH 3/5] update dependencies --- .../plugins/GeneratedPluginRegistrant.java | 4 ++-- android/local.properties | 2 +- ios/Flutter/Generated.xcconfig | 2 +- pubspec.yaml | 18 ++++++++++-------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index 39cea5a..ea1cc21 100644 --- a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -1,7 +1,7 @@ package io.flutter.plugins; import io.flutter.plugin.common.PluginRegistry; -import com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin; +import com.baseflow.geolocator.GeolocatorPlugin; import com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin; import com.baseflow.location_permissions.LocationPermissionsPlugin; @@ -13,7 +13,7 @@ public static void registerWith(PluginRegistry registry) { if (alreadyRegisteredWith(registry)) { return; } - GeolocatorPlugin.registerWith(registry.registrarFor("com.baseflow.flutter.plugin.geolocator.GeolocatorPlugin")); + GeolocatorPlugin.registerWith(registry.registrarFor("com.baseflow.geolocator.GeolocatorPlugin")); GoogleApiAvailabilityPlugin.registerWith(registry.registrarFor("com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin")); LocationPermissionsPlugin.registerWith(registry.registrarFor("com.baseflow.location_permissions.LocationPermissionsPlugin")); } diff --git a/android/local.properties b/android/local.properties index 7cc1df3..faa4197 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,4 +1,4 @@ -sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\sdk +sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\Sdk flutter.sdk=C:\\flutter flutter.buildMode=debug flutter.versionName=1.0.0 diff --git a/ios/Flutter/Generated.xcconfig b/ios/Flutter/Generated.xcconfig index d5e657b..b5d7c82 100644 --- a/ios/Flutter/Generated.xcconfig +++ b/ios/Flutter/Generated.xcconfig @@ -1,7 +1,7 @@ // This is a generated file; do not edit or check into version control. FLUTTER_ROOT=C:\flutter FLUTTER_APPLICATION_PATH=C:\Projects\dart\Weather_Tutorial -FLUTTER_TARGET=lib/main.dart +FLUTTER_TARGET=lib\main.dart FLUTTER_BUILD_DIR=build SYMROOT=${SOURCE_ROOT}/../build\ios FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios diff --git a/pubspec.yaml b/pubspec.yaml index cf7e87a..1530cc1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.2.0 <3.0.0" + sdk: ">=2.3.0 <3.0.0" dependencies: flutter: @@ -18,17 +18,19 @@ dependencies: cupertino_icons: ^0.1.2 - json_annotation: ^2.2.0 - rx_command: ^4.3.0 + json_annotation: ^2.4.0 + rx_command: ^4.3.1 rx_widgets: ^2.2.0 - geolocator: ^4.0.2 + geolocator: ^5.1.0 + # geolocation: "^0.2.1" - rxdart: ^0.20.0 + rxdart: ^0.22.0 + dev_dependencies: - build_runner: ^1.4.0 - json_serializable: ^2.2.2 - intl_translation: ^0.17.4 + build_runner: ^1.6.1 + json_serializable: ^3.0.0 + intl_translation: ^0.17.5 flutter_test: From 7ccab8226bc64e161a07c9613299bdaf6933417d Mon Sep 17 00:00:00 2001 From: tensor-programming Date: Wed, 4 Dec 2019 11:02:36 -0500 Subject: [PATCH 4/5] update dependencies and provider --- .gitignore | 7 +++++++ android/gradle.properties | 3 ++- android/local.properties | 2 +- ios/Runner/GeneratedPluginRegistrant.h | 3 +++ ios/Runner/GeneratedPluginRegistrant.m | 15 +++++++++++++++ lib/const.dart | 2 +- lib/model/model_provider.dart | 8 ++++---- pubspec.yaml | 10 +++++----- 8 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50f15ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.dart_tool/ +build/ +pubspec.lock +.flutter-plugins +.flutter-plugins-dependencies +.packages +android/.gradle \ No newline at end of file diff --git a/android/gradle.properties b/android/gradle.properties index 76cfc20..2a7ccd6 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true +android.enableR8=true diff --git a/android/local.properties b/android/local.properties index faa4197..b27cb4d 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,5 +1,5 @@ sdk.dir=C:\\Users\\jking\\AppData\\Local\\Android\\Sdk -flutter.sdk=C:\\flutter +flutter.sdk=c:\\flutter flutter.buildMode=debug flutter.versionName=1.0.0 flutter.versionCode=1 \ No newline at end of file diff --git a/ios/Runner/GeneratedPluginRegistrant.h b/ios/Runner/GeneratedPluginRegistrant.h index 3b700eb..ed9a5c6 100644 --- a/ios/Runner/GeneratedPluginRegistrant.h +++ b/ios/Runner/GeneratedPluginRegistrant.h @@ -7,8 +7,11 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface GeneratedPluginRegistrant : NSObject + (void)registerWithRegistry:(NSObject*)registry; @end +NS_ASSUME_NONNULL_END #endif /* GeneratedPluginRegistrant_h */ diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m index afb0da8..c20fe77 100644 --- a/ios/Runner/GeneratedPluginRegistrant.m +++ b/ios/Runner/GeneratedPluginRegistrant.m @@ -3,9 +3,24 @@ // #import "GeneratedPluginRegistrant.h" + +#if __has_include() #import +#else +@import geolocator; +#endif + +#if __has_include() #import +#else +@import google_api_availability; +#endif + +#if __has_include() #import +#else +@import location_permissions; +#endif @implementation GeneratedPluginRegistrant diff --git a/lib/const.dart b/lib/const.dart index b6e19dc..13c4cc9 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -1 +1 @@ -const API_KEY = '[Your API KEY]'; +const API_KEY = 'a36c098a4a27c22e4afeae0f05b26a67'; diff --git a/lib/model/model_provider.dart b/lib/model/model_provider.dart index 147f45b..02d3018 100644 --- a/lib/model/model_provider.dart +++ b/lib/model/model_provider.dart @@ -15,10 +15,10 @@ class ModelProvider extends InheritedWidget { return modelCommand != oldWidget.modelCommand; } - static ModelCommand of(BuildContext context) { - ModelProvider modelProvider = - context.inheritFromWidgetOfExactType(ModelProvider) as ModelProvider; + static ModelCommand of(BuildContext context) { + final ModelProvider inherited = + context.dependOnInheritedWidgetOfExactType(); - return modelProvider.modelCommand; + return inherited?.modelCommand; } } diff --git a/pubspec.yaml b/pubspec.yaml index 1530cc1..9a2dc6b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,13 +18,13 @@ dependencies: cupertino_icons: ^0.1.2 - json_annotation: ^2.4.0 - rx_command: ^4.3.1 - rx_widgets: ^2.2.0 - geolocator: ^5.1.0 + json_annotation: ^3.0.0 + rx_command: ^4.3.3 + rx_widgets: ^2.5.0 + geolocator: ^5.1.5 # geolocation: "^0.2.1" - rxdart: ^0.22.0 + rxdart: ^0.22.6 dev_dependencies: From 0ce75fb636e56652bd49b51123a3cdff20bd1e42 Mon Sep 17 00:00:00 2001 From: tensor-programming Date: Wed, 4 Dec 2019 11:06:21 -0500 Subject: [PATCH 5/5] small updates --- lib/main.dart | 98 ++++++++++++++++------------------- lib/model/model_provider.dart | 2 +- 2 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 676962d..65c63a8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -49,12 +49,11 @@ class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { Locale myLocale = Localizations.localeOf(context); + ModelCommand command = ModelProvider.of(context); //call to getGpsCommand handler on build. If GPS is active comes back with true, else false. - ModelProvider.of(context) - .changeLocaleCommand - .call(myLocale.languageCode.toString()); - ModelProvider.of(context).getGpsCommand.call(); + command.changeLocaleCommand.call(myLocale.languageCode.toString()); + command.getGpsCommand.call(); return Scaffold( appBar: AppBar( @@ -72,18 +71,17 @@ class MyHomePage extends StatelessWidget { child: Center( child: RxLoader( radius: 20.0, - commandResults: ModelProvider.of(context).getGpsCommand.results, + commandResults: command.getGpsCommand.results, dataBuilder: (context, data) => Row( - children: [ - Text(data ? "GPS is Active" : "GPS is Inactive"), - // Added logic to change the Icon when GPS is inactive. - IconButton( - icon: Icon( - data ? Icons.gps_fixed : Icons.gps_not_fixed), - onPressed: ModelProvider.of(context).getGpsCommand, - ), - ], + children: [ + Text(data ? "GPS is Active" : "GPS is Inactive"), + // Added logic to change the Icon when GPS is inactive. + IconButton( + icon: Icon(data ? Icons.gps_fixed : Icons.gps_not_fixed), + onPressed: command.getGpsCommand, ), + ], + ), placeHolderBuilder: (context) => Text("Push the Button"), errorBuilder: (context, exception) => Text("$exception"), ), @@ -114,8 +112,7 @@ class MyHomePage extends StatelessWidget { Expanded( child: RxLoader>( radius: 30.0, - commandResults: - ModelProvider.of(context).updateWeatherCommand.results, + commandResults: command.updateWeatherCommand.results, dataBuilder: (context, data) => WeatherList(data), placeHolderBuilder: (context) => Center(child: Text("No Data")), errorBuilder: (context, exception) => @@ -129,15 +126,12 @@ class MyHomePage extends StatelessWidget { //changed to expanded for more consistency. Expanded( child: WidgetSelector( - buildEvents: ModelProvider.of(context) - .updateWeatherCommand - .canExecute, + buildEvents: command.updateWeatherCommand.canExecute, onTrue: MaterialButton( elevation: 5.0, color: Colors.blueGrey, child: Text(AppLocalizations.of(context).button), - onPressed: - ModelProvider.of(context).updateLocationCommand.call, + onPressed: command.updateLocationCommand.call, ), onFalse: MaterialButton( elevation: 0.0, @@ -153,7 +147,7 @@ class MyHomePage extends StatelessWidget { children: [ SliderItem( sliderState: true, - command: ModelProvider.of(context).radioCheckedCommand, + command: command.radioCheckedCommand, ), Container( padding: EdgeInsets.all(10.0), @@ -180,39 +174,37 @@ class WeatherList extends StatelessWidget { return ListView.builder( itemCount: list.length, itemBuilder: (context, index) => ListTile( - leading: Image.network("http://openweathermap.org/img/w/" + - list[index].icon.toString() + - '.png'), - title: Container( - padding: EdgeInsets.all(10.0), - child: Text(list[index].city.toString()), - ), - subtitle: Container( - padding: EdgeInsets.all(10.0), - child: Text(list[index].temperature.toStringAsFixed(2)), - ), - trailing: Container( - child: Column( - children: [ - Text(list[index].description), - Container( - padding: EdgeInsets.only(top: 5.0), - child: Text( - 'Latitude: ${list[index].lat}', - style: TextStyle( - fontSize: 12.0, fontStyle: FontStyle.italic), - ), - ), - Container( - child: Text( - 'Longitude: ${list[index].long}', - style: - TextStyle(fontSize: 12.0, fontStyle: FontStyle.italic), - )) - ], + leading: Image.network("http://openweathermap.org/img/w/" + + list[index].icon.toString() + + '.png'), + title: Container( + padding: EdgeInsets.all(10.0), + child: Text(list[index].city.toString()), + ), + subtitle: Container( + padding: EdgeInsets.all(10.0), + child: Text(list[index].temperature.toStringAsFixed(2)), + ), + trailing: Container( + child: Column( + children: [ + Text(list[index].description), + Container( + padding: EdgeInsets.only(top: 5.0), + child: Text( + 'Latitude: ${list[index].lat}', + style: TextStyle(fontSize: 12.0, fontStyle: FontStyle.italic), + ), ), - ), + Container( + child: Text( + 'Longitude: ${list[index].long}', + style: TextStyle(fontSize: 12.0, fontStyle: FontStyle.italic), + )) + ], ), + ), + ), ); } } diff --git a/lib/model/model_provider.dart b/lib/model/model_provider.dart index 02d3018..51bcd36 100644 --- a/lib/model/model_provider.dart +++ b/lib/model/model_provider.dart @@ -15,7 +15,7 @@ class ModelProvider extends InheritedWidget { return modelCommand != oldWidget.modelCommand; } - static ModelCommand of(BuildContext context) { + static ModelCommand of(BuildContext context) { final ModelProvider inherited = context.dependOnInheritedWidgetOfExactType();