Skip to content

Commit

Permalink
ask location permission (fixes #43, #45, #48, #51) (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: rrijal53 <[email protected]>
  • Loading branch information
ComputerOnFire and rrijal53 authored Nov 13, 2021
1 parent fc2ced9 commit c78c887
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 86 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: subosito/flutter-action@v1
with:
channel: 'stable'
flutter-version: '2.2.0'
flutter-version: '2.5.2'

- run: |
flutter clean
Expand All @@ -39,7 +39,13 @@ jobs:
- uses: subosito/flutter-action@v1
with:
channel: 'stable' # 'dev', 'alpha', default to: 'stable'
flutter-version: '2.2.0' # you can also specify exact version of flutter
flutter-version: '2.5.2' # you can also specify exact version of flutter

- run: |
flutter clean
flutter pub get
flutter build ios --release --no-codesign
cd ios
pod install
- run: flutter build ios --release --no-codesign
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,7 +36,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "io.treehouses.remoteii"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
13 changes: 9 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.treehouses.remoteble.treehousesble">

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:label="Treehouses RemoteII"
android:icon="@mipmap/launcher_icon">

<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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ subprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

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"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>10.0</string>
</dict>
</plist>
63 changes: 60 additions & 3 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down Expand Up @@ -37,5 +36,63 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
# Here are some configurations automatically generated by flutter

# You can enable the permissions needed here. For example to enable camera
# permission, just remove the `#` character in front so it looks like this:
#
# ## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1'
#
# Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=1',

## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=1',

## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=1',

## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1',

## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=1',

## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=1',

## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=1',

## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',

## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=1',

## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=1',

## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=1',

## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=1',

## dart: PermissionGroup.appTrackingTransparency
# 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

## dart: PermissionGroup.criticalAlerts
# 'PERMISSION_CRITICAL_ALERTS=1'
]

end
end
end
end
16 changes: 11 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ PODS:
- Flutter
- path_provider (0.0.1):
- Flutter
- "permission_handler (5.1.0+2)":
- Flutter
- Protobuf (3.11.4)
- shared_preferences (0.0.1):
- Flutter
Expand All @@ -21,6 +23,7 @@ DEPENDENCIES:
- flutter_blue (from `.symlinks/plugins/flutter_blue/ios`)
- package_info (from `.symlinks/plugins/package_info/ios`)
- path_provider (from `.symlinks/plugins/path_provider/ios`)
- permission_handler (from `.symlinks/plugins/permission_handler/ios`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)

Expand All @@ -37,20 +40,23 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/package_info/ios"
path_provider:
:path: ".symlinks/plugins/path_provider/ios"
permission_handler:
:path: ".symlinks/plugins/permission_handler/ios"
shared_preferences:
:path: ".symlinks/plugins/shared_preferences/ios"
url_launcher:
:path: ".symlinks/plugins/url_launcher/ios"

SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_blue: eeb381dc4727a0954dede73515f683865494b370
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
path_provider: d1e9807085df1f9cc9318206cd649dc0b76be3de
permission_handler: ccb20a9fad0ee9b1314a52b70b76b473c5f8dab0
Protobuf: 176220c526ad8bd09ab1fb40a978eac3fef665f7
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
shared_preferences: 5033afbb22d372e15aff8ff766df9021b845f273
url_launcher: b6e016d912f04be9f5bf6e8e82dc599b7ba59649

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
PODFILE CHECKSUM: d4807ef77006891d298ba2f893031d4f0cd35075

COCOAPODS: 1.10.2
30 changes: 21 additions & 9 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -121,7 +121,6 @@
0790B6FC0CD83AFFF907B93D /* Pods-Runner.release.xcconfig */,
6CCBBC19E381606D430444C9 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -340,7 +339,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -358,7 +357,11 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = io.treehouses.remoteii;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -414,7 +417,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -463,11 +466,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -482,7 +486,11 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = io.treehouses.remoteii;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -501,7 +509,11 @@
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = io.treehouses.remoteii;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
8 changes: 0 additions & 8 deletions ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

This file was deleted.

This file was deleted.

20 changes: 16 additions & 4 deletions lib/common/bloc/bluetooth_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:bloc/bloc.dart';
import 'package:flutter_blue/flutter_blue.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:treehousesble/app/app.dart';
import 'package:treehousesble/common/bloc/bluetooth_state.dart';
import 'package:treehousesble/common/constants/app_constants.dart';
Expand All @@ -18,10 +19,21 @@ class BluetoothCubit extends Cubit<DataState> {

appStart() async {
final bool firstTimeAppOpen = await SharedPref.getFirstTimeAppOpen();
if (firstTimeAppOpen) {
emit(FirstTimeAppOpen());
} else {
emit(NotFirstTimeAppOpen());
Map<Permission, PermissionStatus> statuses = await [
Permission.location,
Permission.bluetoothScan,
Permission.bluetoothConnect,
].request();
if(statuses[Permission.location] == PermissionStatus.granted
&& statuses[Permission.bluetoothScan] == PermissionStatus.granted
&& statuses[Permission.bluetoothConnect] == PermissionStatus.granted){
if (firstTimeAppOpen) {
emit(FirstTimeAppOpen());
} else {
emit(NotFirstTimeAppOpen());
}
} else{
emit(PermissionsNotGranted());
}
}
List<int> _sendCommand(String command) {
Expand Down
5 changes: 4 additions & 1 deletion lib/common/bloc/bluetooth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class FirstTimeAppOpen extends DataState {
List<Object> get props => [];
}


class NotFirstTimeAppOpen extends DataState {
@override
List<Object> get props => [];
}

class PermissionsNotGranted extends DataState {
@override
List<Object> get props => [];
}

class StateIniital extends DataState {}

Expand Down
1 change: 0 additions & 1 deletion lib/feature/onboard/ui/screen/landing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:treehousesble/common/bloc/bluetooth_cubit.dart';
import 'package:treehousesble/common/bloc/bluetooth_state.dart';
import 'package:treehousesble/feature/dashboard/screen/dashboard_page.dart';
import 'package:treehousesble/feature/dashboard/screen/search_rpi_screen.dart';

import 'onboard_page.dart';
Expand Down
Loading

0 comments on commit c78c887

Please sign in to comment.