Selaa lähdekoodia

updates to the example project

Luke 7 vuotta sitten
vanhempi
commit
a0776a51ce

+ 15 - 0
.vscode/launch.json

@@ -0,0 +1,15 @@
+{
+	// Use IntelliSense to learn about possible attributes.
+	// Hover to view descriptions of existing attributes.
+	// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+	"version": "0.2.0",
+	"configurations": [
+		{
+			"name": "Flutter",
+			"request": "launch",
+			"type": "dart",
+			"cwd" : "${workspaceRoot}/example",
+			"program": "${workspaceRoot}/example/lib/main.dart"
+		}
+	]
+}

+ 13 - 0
example/.vscode/launch.json

@@ -0,0 +1,13 @@
+{
+	// Use IntelliSense to learn about possible attributes.
+	// Hover to view descriptions of existing attributes.
+	// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+	"version": "0.2.0",
+	"configurations": [
+		{
+			"name": "Flutter",
+			"request": "launch",
+			"type": "dart"
+		}
+	]
+}

+ 34 - 93
example/android/app/build.gradle

@@ -1,101 +1,42 @@
-// flutter
-def localProperties = new Properties()
-def localPropertiesFile = rootProject.file('local.properties')
-if (localPropertiesFile.exists()) {
-    localPropertiesFile.withInputStream { stream ->
-        localProperties.load(stream)
-    }
-}
-
-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.")
-}
-
 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
-apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
-
-flutter {
-    source '../..'
-}
-
-// build versioning
-def currentVersionCode() {
-    def propsFile = file('versions.properties')
-    def props = new Properties()
-    props.load(new FileInputStream(propsFile))
-    return props['build.versionCode'].toInteger()
-}
-
-def incrementVersionCode() {
-    def propsFile = file('versions.properties')
-    def props = new Properties()
-    props.load(new FileInputStream(propsFile))
-    def currentCode = props['build.versionCode'].toInteger()
-    def nextCode = currentCode + 1
-    props['build.versionCode'] = nextCode.toString()
-    props.store(propsFile.newWriter(), null)
-    return nextCode
-}
-
-// increments build version code on release builds
-task('incrementVersionCode') << {
-    incrementVersionCode()
-}
-
-tasks.whenTaskAdded { task ->
-    if (task.name == 'assembleRelease') {
-        task.dependsOn 'incrementVersionCode'
-    }
-}
-
-buildscript {
-    // application variables
-    ext.app_ver_name = "1.0"
-
-    // google version codes
-    ext.build_tools_ver = '25.0.3'
-    ext.support_lib_ver = '25.3.1'
-    ext.google_play_ver = '10.2.4'
-    ext.constraint_layout_ver = '1.0.2'
-}
+apply from: "../config.gradle"
+apply from: "../flutter.gradle"
 
 android {
-    compileSdkVersion 25
-    buildToolsVersion "$build_tools_ver"
-
-    defaultConfig {
-        minSdkVersion 19
-        targetSdkVersion 25
-        applicationId "com.goposse.routersample"
-        versionCode currentVersionCode()
-        versionName "$app_ver_name"
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
-    }
-    lintOptions {
-        disable 'InvalidPackage'
-    }
-    buildTypes {
-        release {
-            // TODO: Add your own signing config for the release build.
-            // Signing with the debug keys for now, so `flutter run --release` works.
-            signingConfig signingConfigs.debug
-        }
-    }
+	compileSdkVersion versions.targetSDK
+	buildToolsVersion "${versions.buildTools}"
+
+	defaultConfig {
+		minSdkVersion versions.minSDK
+		targetSdkVersion versions.targetSDK
+		applicationId "$appInfo.applicationID"
+		versionCode appInfo.build
+		versionName "${appInfo.version}"
+		testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
+	}
+	lintOptions {
+		disable 'InvalidPackage'
+	}
+	buildTypes {
+		release {
+			// TODO: Add your own signing config for the release build.
+			// Signing with the debug keys for now, so `flutter run --release` works.
+			signingConfig signingConfigs.debug
+		}
+	}
 }
 
 dependencies {
-    compile fileTree(dir: 'libs', include: ['*.jar'])
-
-    // google
-    compile "com.android.support:appcompat-v7:$support_lib_ver"
-    compile "com.android.support:support-v13:$support_lib_ver"
-    compile "com.android.support:support-v4:$support_lib_ver"
-
-    // testing
-    androidTestCompile "com.android.support:support-annotations:$support_lib_ver"
-    androidTestCompile 'com.android.support.test:runner:0.5'
-    androidTestCompile 'com.android.support.test:rules:0.5'
-	compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
+	compile fileTree(dir: 'libs', include: ['*.jar'])
+	// kotlin
+	compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
+	// google
+	compile "com.android.support:appcompat-v7:${versions.googleSupport}"
+	compile "com.android.support:support-v13:${versions.googleSupport}"
+	compile "com.android.support:support-v4:${versions.googleSupport}"
+	// testing
+	androidTestCompile "com.android.support:support-annotations:${versions.googleSupport}"
+	androidTestCompile 'com.android.support.test:runner:1.0.1'
+	androidTestCompile 'com.android.support.test:rules:1.0.1'
 }

+ 4 - 4
example/android/app/src/main/AndroidManifest.xml

@@ -1,16 +1,16 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    package="com.goposse.routersample">
+    package="com.goposse.fluro">
 
     <!-- needed for flutter development tools -->
     <uses-permission android:name="android.permission.INTERNET" />
 
     <application
-        android:name=".App"
+        android:name="com.goposse.fluro.App"
         android:allowBackup="false"
         android:icon="@mipmap/ic_launcher"
         android:label="@string/appName">
         <activity
-            android:name=".activities.MainActivity"
+            android:name="com.goposse.fluro.activities.MainActivity"
             android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
             android:hardwareAccelerated="true"
             android:theme="@android:style/Theme.Black.NoTitleBar"
@@ -23,7 +23,7 @@
                 <action android:name="android.intent.action.VIEW" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.BROWSABLE" />
-                <data android:host="link" android:scheme="fluro" />
+                <data android:host="deeplink" android:scheme="fluro" />
             </intent-filter>
         </activity>
     </application>

+ 1 - 1
example/android/app/src/main/java/com/goposse/routersample/App.kt → example/android/app/src/main/java/com/goposse/fluro/App.kt

@@ -1,4 +1,4 @@
-package com.goposse.routersample
+package com.goposse.fluro
 
 import io.flutter.app.FlutterApplication
 

+ 5 - 15
example/android/app/src/main/java/com/goposse/routersample/activities/MainActivity.kt → example/android/app/src/main/java/com/goposse/fluro/activities/MainActivity.kt

@@ -1,43 +1,33 @@
-package com.goposse.routersample.activities
+package com.goposse.fluro.activities
 
 import android.content.Intent
-import android.net.Uri
 import android.os.Bundle
 import android.util.Log
 
-import com.goposse.routersample.constants.Channels
-
 import io.flutter.app.FlutterActivity
-import io.flutter.plugin.common.MethodChannel
 import io.flutter.plugins.GeneratedPluginRegistrant
 
 class MainActivity : FlutterActivity() {
 
 	private val LOG_TAG = "A:Main"
-	private var deepLinkChannel: MethodChannel? = null
 
 	override fun onCreate(savedInstanceState: Bundle?) {
 		super.onCreate(savedInstanceState)
 		GeneratedPluginRegistrant.registerWith(this)
-		deepLinkChannel = MethodChannel(flutterView, Channels.DEEP_LINK_RECEIVED)
+		checkForLinkEvent(intent)
 	}
 
 	override fun onResume() {
 		super.onResume()
-		checkForLinkEvent(intent)
 	}
 
 	private fun checkForLinkEvent(intent: Intent) {
 		if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
 			val path = intent.data.getQueryParameter("path")
-			val query = intent.data.getQueryParameter("query")
+			val text = intent.data.getQueryParameter("message") ?: "Why you don't enter text?"
 			if (path != null) {
-				val passedObjs = mutableMapOf<String, Any>("path" to path)
-				if (query != null) {
-					passedObjs["query"] = query
-				}
-				deepLinkChannel?.invokeMethod("linkReceived", passedObjs)
-				Log.d(LOG_TAG, "Sent message to flutter: linkReceived=$path")
+				Log.d(LOG_TAG, "Setting initial route to: $path?message=$text")
+				flutterView.setInitialRoute("$path?message=$text")
 			}
 		}
 	}

+ 1 - 1
example/android/app/src/main/java/com/goposse/routersample/constants/Channels.kt → example/android/app/src/main/java/com/goposse/fluro/constants/Channels.kt

@@ -1,4 +1,4 @@
-package com.goposse.routersample.constants
+package com.goposse.fluro.constants
 
 object Channels {
 	private val CHANNEL_PREFIX = "channel:com.goposse.routersample"

+ 4 - 5
example/android/build.gradle

@@ -1,21 +1,20 @@
 buildscript {
-	ext.kotlin_version = '1.1.3-2'
+	ext.kotlin_version = '1.2.30'
 	repositories {
+		google()
         jcenter()
 	}
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.3.3'
+        classpath 'com.android.tools.build:gradle:3.0.1'
 		classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 	}
 }
 
 allprojects {
     repositories {
+		google()
         jcenter()
-        maven {
-            url "https://maven.google.com"
-        }
     }
 }
 

+ 13 - 0
example/android/config.gradle

@@ -0,0 +1,13 @@
+ext.appInfo = [
+		version: '1.3.0',
+		build: 1,
+		applicationID: "com.goposse.fluro"
+]
+
+ext.versions = [
+		minSDK: 21,
+		targetSDK: 27,
+		buildTools: '27.0.3',
+		kotlin: '1.2.30',
+		googleSupport: '27.1.0'
+]

+ 22 - 0
example/android/flutter.gradle

@@ -0,0 +1,22 @@
+// Flutter root path helper
+ext.flutterRoot = {
+	def flutterProperties = new Properties()
+	def flutterPropertiesFile = rootProject.file('local.properties')
+	if (!flutterPropertiesFile.exists()) {
+		throw new GradleException("Flutter properties file not found. Define a flutter.properties file in your project root.")
+	}
+	flutterPropertiesFile.withInputStream { stream ->
+		flutterProperties.load(stream)
+	}
+	def flutterRoot = flutterProperties.getProperty('flutter.sdk')
+	if (flutterRoot == null) {
+		throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the flutter.properties file.")
+	}
+	return flutterRoot
+}
+
+apply from: "${flutterRoot()}/packages/flutter_tools/gradle/flutter.gradle"
+
+flutter {
+	source '../..'
+}

+ 5 - 20
example/lib/components/app/app_component.dart

@@ -7,7 +7,6 @@
  */
 import '../../config/application.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
 import 'package:fluro/fluro.dart';
 import '../../config/routes.dart';
 import '../home/home_component.dart';
@@ -22,38 +21,24 @@ class AppComponent extends StatefulWidget {
 
 class AppComponentState extends State<AppComponent> {
 
-  static MethodChannel platform = const MethodChannel('channel:com.goposse.routersample/deeplink');
-
   AppComponentState() {
     final router = new Router();
     Routes.configureRoutes(router);
     Application.router = router;
-    configureDeepLinker();
-    print("Configured channel receiver in flutter ..");
   }
 
 
-  void configureDeepLinker() {
-    platform.setMethodCallHandler((MethodCall call) async {
-      if (call.method == "linkReceived") {
-        Map<String, dynamic> passedObjs = call.arguments;
-        if (passedObjs != null) {
-          var path = passedObjs["path"];
-          Application.router.navigateTo(context, path);
-        }
-      }
-    });
-  }
-
   @override
   Widget build(BuildContext context) {
-    return new MaterialApp(
-      title: 'Flutter Demo',
+    final app = new MaterialApp(
+      title: 'Fluro',
       theme: new ThemeData(
         primarySwatch: Colors.blue,
       ),
-      home: new HomeComponent(),
+      onGenerateRoute: Application.router.generator
     );
+    print("initial route = ${app.initialRoute}");
+    return app;
   }
 }
 

+ 15 - 0
example/lib/components/demo/demo_result_component.dart

@@ -0,0 +1,15 @@
+import 'package:flutter/material.dart';
+
+class DemoResultComponent extends StatefulWidget {
+  @override
+  _DemoResultComponentState createState() => new _DemoResultComponentState();
+}
+
+class _DemoResultComponentState extends State<DemoResultComponent> {
+  @override
+  Widget build(BuildContext context) {
+    return new Container(
+      
+    );
+  }
+}

+ 1 - 1
example/lib/components/home/home_component.dart

@@ -21,7 +21,7 @@ class HomeComponent extends StatefulWidget {
 class HomeComponentState extends State<HomeComponent> {
 
   var _deepLinkOpacity = 1.0;
-  final _deepLinkURL = "fluro://deeplink?path=/message&text=fluro%20rocks%21%21";
+  final _deepLinkURL = "fluro://deeplink?path=/message&mesage=fluro%20rocks%21%21";
   final _daysOfWeek = const [
     "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
   ];

+ 19 - 1
example/lib/config/route_handlers.dart

@@ -7,10 +7,15 @@
  */
 import '../helpers/color_helpers.dart';
 import '../components/demo/demo_simple_component.dart';
+import '../components/home/home_component.dart';
 import 'package:flutter/painting.dart';
 import 'package:fluro/fluro.dart';
 import 'package:flutter/material.dart';
 
+var rootHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
+  return new HomeComponent();
+});
+
 var demoRouteHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
   String message = params["message"]?.first;
   String colorHex = params["color_hex"]?.first;
@@ -53,4 +58,17 @@ var demoFunctionHandler = new Handler(
       );
     });
 
-var deepLinkHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {});
+/// Handles deep links into the app
+/// To test on Android:
+/// 
+/// `adb shell am start -W -a android.intent.action.VIEW -d "fluro://deeplink?path=/message&mesage=fluro%20rocks%21%21" com.goposse.fluro`
+var deepLinkHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
+  String message = params["message"]?.first;
+  String colorHex = params["color_hex"]?.first;
+  String result = params["result"]?.first;
+  Color color = new Color(0xFFFFFFFF);
+  if (colorHex != null && colorHex.length > 0) {
+    color = new Color(ColorHelpers.fromHexString(colorHex));
+  }
+  return new DemoSimpleComponent(message: "DEEEEEP LINK!!!", color: color, result: result);  
+});

+ 6 - 0
example/lib/config/routes.dart

@@ -6,15 +6,21 @@
  * See LICENSE for distribution and usage details.
  */
 import 'package:fluro/fluro.dart';
+import 'package:flutter/material.dart';
 import './route_handlers.dart';
 
 class Routes {
 
+  static String root = "/";
   static String demoSimple = "/demo";
   static String demoFunc = "/demo/func";
   static String deepLink = "/message";
 
   static void configureRoutes(Router router) {
+    router.notFoundHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
+      print("ROUTE WAS NOT FOUND !!!");
+    });
+    router.define(root, handler: rootHandler);
     router.define(demoSimple, handler: demoRouteHandler);
     router.define(demoFunc, handler: demoFunctionHandler);
     router.define(deepLink, handler: deepLinkHandler);