updates to the example project

This commit is contained in:
Luke 2018-03-23 08:53:23 -07:00
parent 12cb5317db
commit a0776a51ce
15 changed files with 157 additions and 140 deletions

15
.vscode/launch.json vendored Normal file
View File

@ -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
example/.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

View File

@ -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: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "../config.gradle"
apply from: "../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'
}
android { android {
compileSdkVersion 25 compileSdkVersion versions.targetSDK
buildToolsVersion "$build_tools_ver" buildToolsVersion "${versions.buildTools}"
defaultConfig { defaultConfig {
minSdkVersion 19 minSdkVersion versions.minSDK
targetSdkVersion 25 targetSdkVersion versions.targetSDK
applicationId "com.goposse.routersample" applicationId "$appInfo.applicationID"
versionCode currentVersionCode() versionCode appInfo.build
versionName "$app_ver_name" versionName "${appInfo.version}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
} }
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig signingConfigs.debug
} }
} }
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
// kotlin
// google compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
compile "com.android.support:appcompat-v7:$support_lib_ver" // google
compile "com.android.support:support-v13:$support_lib_ver" compile "com.android.support:appcompat-v7:${versions.googleSupport}"
compile "com.android.support:support-v4:$support_lib_ver" compile "com.android.support:support-v13:${versions.googleSupport}"
compile "com.android.support:support-v4:${versions.googleSupport}"
// testing // testing
androidTestCompile "com.android.support:support-annotations:$support_lib_ver" androidTestCompile "com.android.support:support-annotations:${versions.googleSupport}"
androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile 'com.android.support.test:rules:1.0.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,21 +1,20 @@
buildscript { buildscript {
ext.kotlin_version = '1.1.3-2' ext.kotlin_version = '1.2.30'
repositories { repositories {
google()
jcenter() jcenter()
} }
dependencies { 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" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }
allprojects { allprojects {
repositories { repositories {
google()
jcenter() jcenter()
maven {
url "https://maven.google.com"
}
} }
} }

View File

@ -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'
]

View File

@ -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 '../..'
}

View File

@ -7,7 +7,6 @@
*/ */
import '../../config/application.dart'; import '../../config/application.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluro/fluro.dart'; import 'package:fluro/fluro.dart';
import '../../config/routes.dart'; import '../../config/routes.dart';
import '../home/home_component.dart'; import '../home/home_component.dart';
@ -22,38 +21,24 @@ class AppComponent extends StatefulWidget {
class AppComponentState extends State<AppComponent> { class AppComponentState extends State<AppComponent> {
static MethodChannel platform = const MethodChannel('channel:com.goposse.routersample/deeplink');
AppComponentState() { AppComponentState() {
final router = new Router(); final router = new Router();
Routes.configureRoutes(router); Routes.configureRoutes(router);
Application.router = 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new MaterialApp( final app = new MaterialApp(
title: 'Flutter Demo', title: 'Fluro',
theme: new ThemeData( theme: new ThemeData(
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
home: new HomeComponent(), onGenerateRoute: Application.router.generator
); );
print("initial route = ${app.initialRoute}");
return app;
} }
} }

View File

@ -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(
);
}
}

View File

@ -21,7 +21,7 @@ class HomeComponent extends StatefulWidget {
class HomeComponentState extends State<HomeComponent> { class HomeComponentState extends State<HomeComponent> {
var _deepLinkOpacity = 1.0; 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 [ final _daysOfWeek = const [
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
]; ];

View File

@ -7,10 +7,15 @@
*/ */
import '../helpers/color_helpers.dart'; import '../helpers/color_helpers.dart';
import '../components/demo/demo_simple_component.dart'; import '../components/demo/demo_simple_component.dart';
import '../components/home/home_component.dart';
import 'package:flutter/painting.dart'; import 'package:flutter/painting.dart';
import 'package:fluro/fluro.dart'; import 'package:fluro/fluro.dart';
import 'package:flutter/material.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) { var demoRouteHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
String message = params["message"]?.first; String message = params["message"]?.first;
String colorHex = params["color_hex"]?.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);
});

View File

@ -6,15 +6,21 @@
* See LICENSE for distribution and usage details. * See LICENSE for distribution and usage details.
*/ */
import 'package:fluro/fluro.dart'; import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import './route_handlers.dart'; import './route_handlers.dart';
class Routes { class Routes {
static String root = "/";
static String demoSimple = "/demo"; static String demoSimple = "/demo";
static String demoFunc = "/demo/func"; static String demoFunc = "/demo/func";
static String deepLink = "/message"; static String deepLink = "/message";
static void configureRoutes(Router router) { 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(demoSimple, handler: demoRouteHandler);
router.define(demoFunc, handler: demoFunctionHandler); router.define(demoFunc, handler: demoFunctionHandler);
router.define(deepLink, handler: deepLinkHandler); router.define(deepLink, handler: deepLinkHandler);