Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to flutter 3.0 #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*.iws
.idea/


# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
40 changes: 23 additions & 17 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader)
}
}

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 flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
flutterVersionCode = '1'
flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
flutterVersionName = '1.0'
flutterVersionName = "1.0"
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
namespace = "com.example.example"
compileSdk = 34
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -39,8 +45,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
6 changes: 3 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand Down
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '2.0.20'

repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
}
5 changes: 3 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
30 changes: 20 additions & 10 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
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
}()

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "2.0.20" apply false
}

include ":app"
65 changes: 33 additions & 32 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:google_place/google_place.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await DotEnv().load('.env');
await dotenv.load(fileName: ".env");
runApp(MyApp());
}

Expand All @@ -29,12 +29,13 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
GooglePlace googlePlace;
late GooglePlace googlePlace;
List<AutocompletePrediction> predictions = [];

@override
void initState() {
String apiKey = DotEnv().env['API_KEY'];
String apiKey = dotenv.env['API_KEY'] ?? "";
print(apiKey);
googlePlace = GooglePlace(apiKey);
super.initState();
}
Expand Down Expand Up @@ -90,14 +91,14 @@ class _HomePageState extends State<HomePage> {
color: Colors.white,
),
),
title: Text(predictions[index].description),
title: Text(predictions[index].description ?? ""),
onTap: () {
debugPrint(predictions[index].placeId);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(
placeId: predictions[index].placeId,
placeId: predictions[index].placeId ?? "",
googlePlace: googlePlace,
),
),
Expand All @@ -122,30 +123,30 @@ class _HomePageState extends State<HomePage> {
var result = await googlePlace.autocomplete.get(value);
if (result != null && result.predictions != null && mounted) {
setState(() {
predictions = result.predictions;
predictions = result.predictions ?? [];
});
}
}
}

class DetailsPage extends StatefulWidget {
final String placeId;
final GooglePlace googlePlace;
final String? placeId;
final GooglePlace? googlePlace;

DetailsPage({Key key, this.placeId, this.googlePlace}) : super(key: key);
DetailsPage({Key? key, this.placeId, this.googlePlace}) : super(key: key);

@override
_DetailsPageState createState() =>
_DetailsPageState(this.placeId, this.googlePlace);
}

class _DetailsPageState extends State<DetailsPage> {
final String placeId;
final GooglePlace googlePlace;
final String? placeId;
final GooglePlace? googlePlace;

_DetailsPageState(this.placeId, this.googlePlace);

DetailsResult detailsResult;
DetailsResult? detailsResult;
List<Uint8List> images = [];

@override
Expand Down Expand Up @@ -220,19 +221,19 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
),
detailsResult != null && detailsResult.types != null
detailsResult != null && detailsResult?.types != null
? Container(
margin: EdgeInsets.only(left: 15, top: 10),
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: detailsResult.types.length,
itemCount: detailsResult?.types!.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(right: 10),
child: Chip(
label: Text(
detailsResult.types[index],
detailsResult!.types![index],
style: TextStyle(
color: Colors.white,
),
Expand All @@ -252,8 +253,8 @@ class _DetailsPageState extends State<DetailsPage> {
),
title: Text(
detailsResult != null &&
detailsResult.formattedAddress != null
? 'Address: ${detailsResult.formattedAddress}'
detailsResult!.formattedAddress != null
? 'Address: ${detailsResult!.formattedAddress}'
: "Address: null",
),
),
Expand All @@ -266,9 +267,9 @@ class _DetailsPageState extends State<DetailsPage> {
),
title: Text(
detailsResult != null &&
detailsResult.geometry != null &&
detailsResult.geometry.location != null
? 'Geometry: ${detailsResult.geometry.location.lat.toString()},${detailsResult.geometry.location.lng.toString()}'
detailsResult!.geometry != null &&
detailsResult!.geometry!.location != null
? 'Geometry: ${detailsResult!.geometry!.location!.lat.toString()},${detailsResult!.geometry!.location!.lng.toString()}'
: "Geometry: null",
),
),
Expand All @@ -281,8 +282,8 @@ class _DetailsPageState extends State<DetailsPage> {
),
title: Text(
detailsResult != null &&
detailsResult.utcOffset != null
? 'UTC offset: ${detailsResult.utcOffset.toString()} min'
detailsResult!.utcOffset != null
? 'UTC offset: ${detailsResult!.utcOffset.toString()} min'
: "UTC offset: null",
),
),
Expand All @@ -295,8 +296,8 @@ class _DetailsPageState extends State<DetailsPage> {
),
title: Text(
detailsResult != null &&
detailsResult.rating != null
? 'Rating: ${detailsResult.rating.toString()}'
detailsResult!.rating != null
? 'Rating: ${detailsResult!.rating.toString()}'
: "Rating: null",
),
),
Expand All @@ -309,8 +310,8 @@ class _DetailsPageState extends State<DetailsPage> {
),
title: Text(
detailsResult != null &&
detailsResult.priceLevel != null
? 'Price level: ${detailsResult.priceLevel.toString()}'
detailsResult!.priceLevel != null
? 'Price level: ${detailsResult!.priceLevel.toString()}'
: "Price level: null",
),
),
Expand All @@ -330,24 +331,24 @@ class _DetailsPageState extends State<DetailsPage> {
);
}

void getDetils(String placeId) async {
var result = await this.googlePlace.details.get(placeId);
void getDetils(String? placeId) async {
var result = await this.googlePlace?.details.get(placeId ?? "");
if (result != null && result.result != null && mounted) {
setState(() {
detailsResult = result.result;
images = [];
});

if (result.result.photos != null) {
for (var photo in result.result.photos) {
getPhoto(photo.photoReference);
if (result.result!.photos != null) {
for (var photo in result.result!.photos!) {
getPhoto(photo.photoReference!);
}
}
}
}

void getPhoto(String photoReference) async {
var result = await this.googlePlace.photos.get(photoReference, null, 400);
var result = await this.googlePlace!.photos.get(photoReference, 400, 400);
if (result != null && mounted) {
setState(() {
images.add(result);
Expand Down
Loading