Skip to content

Commit

Permalink
rename. add example project
Browse files Browse the repository at this point in the history
  • Loading branch information
lukef committed May 14, 2017
1 parent 91c2142 commit 32d91dc
Show file tree
Hide file tree
Showing 70 changed files with 1,644 additions and 25 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# mac system
.DS_Store

# intellij
.idea

# dart / flutter
.packages
pubspec.lock
coverage
__temp_coverage*
__temp_coverage*
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# Router
<img src="https://storage.googleapis.com/app-logos/logo_fluro.png" width="220">
<br/><br/>

The brightest, hippest, coolest router for Flutter.

[![Build Status](https://travis-ci.org/goposse/flutter-router.svg?branch=master)](https://travis-ci.org/goposse/flutter-router)
[![codecov](https://codecov.io/gh/goposse/flutter-router/branch/master/graph/badge.svg)](https://codecov.io/gh/goposse/flutter-router)
[![Coverage](https://codecov.io/gh/goposse/flutter-router/branch/master/graph/badge.svg)](https://codecov.io/gh/goposse/flutter-router)

## Features

- Simple route navigation
- Wildcard parameter matching
- Querystring parameter parsing
- Common transitions built-in
- Simple custom transition creation

## Getting started

You should ensure that you add the router as a dependency in your flutter project.
Currently, you will need to add the git repo directly. A submitted pub package will
be available soon.

To add the dependency directly:


You should ensure that you add the router as a dependency in your flutter project.
Currently, you will need to add the git repo directly. A submitted pub package will be available **soon**.

To add the dependency directly:

```yaml
dependencies:
router:
fluro:
git: git://github.com/goposse/flutter-router.git
```
You should then run `pub update` or update your packages in IntelliJ.
You should then run `flutter packages upgrade` or update your packages in IntelliJ.

## Example Project

There is a pretty sweet example project in the `example` folder. Check it out. Otherwise, keep reading to get up and running.

## Setting up

First, you should define a new `Router` object by initializing it as such:
First, you should define a new `Router` object by initializing it as such:
```dart
final Router router = new Router();
```
Expand All @@ -38,21 +52,22 @@ void defineRoutes(Router router) {
}
```

In the above example, the router will intercept a route such as
In the above example, the router will intercept a route such as
`/users/1234` and route the application to the `UsersScreen` passing
the value `1234` as a parameter to that screen.

## Navigating

You can use the `Router` with the `MaterialApp.onGenerateRoute` parameter
via the `Router.generator` function. To do so, pass the function reference to
the `onGenerate` parameter like: `onGenerateRoute: router.generator`.
via the `Router.generator` function. To do so, pass the function reference to
the `onGenerate` parameter like: `onGenerateRoute: router.generator`.

You can then use `Navigator.push` and the flutter routing mechanism will match the routes
for you.
for you.

You can also manually push to a route yourself. To do so:

```dart
router.navigateTo(context, "/users/1234");
```
router.navigateTo(context, "/users/1234",
transition: TransitionType.fadeIn);
```
49 changes: 49 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.DS_Store

.atom/
.idea
.packages
.pub/
build/
ios/.generated/
packages
pubspec.lock
.flutter-plugins

# temporary
Podfile.lock

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xcuserstate

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/
12 changes: 12 additions & 0 deletions example/android.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/android">
<sourceFolder url="file://$MODULE_DIR$/android/app/src/main/java" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Flutter for Android" level="project" />
</component>
</module>
13 changes: 13 additions & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
PluginRegistry.java

/gradle
/gradlew
/gradlew.bat
103 changes: 103 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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 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'
}

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'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
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'
}
32 changes: 32 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.goposse.routersample">

<!-- needed for flutter development tools -->
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName">
<activity
android:name=".activities.MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<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="woomera" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.goposse.routersample;

import io.flutter.app.FlutterApplication;

public class App extends FlutterApplication {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.goposse.routersample.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.PluginRegistry;

public class MainActivity extends FlutterActivity {

private static final String LOG_TAG = "A:Main";

PluginRegistry pluginRegistry;
private static MethodChannel deepLinkChannel;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pluginRegistry = new PluginRegistry();
pluginRegistry.registerAll(this);

if (deepLinkChannel == null) {
deepLinkChannel = new MethodChannel(getFlutterView(), Channels.DEEP_LINK_RECEIVED);
}

Intent intent = getIntent();
checkForLinkEvent(intent);
}

private void checkForLinkEvent(Intent intent) {
String action = intent.getAction();
Log.d(LOG_TAG, "Hey!!! " + action);
if (action.equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
if (data != null) {
String path = data.getQueryParameter("path");
if (path != null) {
Log.d(LOG_TAG, String.format("Received external link: %s", data.toString()));
deepLinkChannel.invokeMethod("linkReceived", path);
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.goposse.routersample.constants;

public class Channels {
private static final String CHANNEL_PREFIX = "channel:com.goposse.routerdemo";
public static final String DEEP_LINK_RECEIVED = CHANNEL_PREFIX + "/deeplink";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.flutter.plugins;

import io.flutter.plugin.common.PluginRegistry;

/**
* Generated file. Do not edit.
*/
public final class GeneratedPluginRegistrant {
public static void registerWith(PluginRegistry registry) {
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="appName">Router Sample</string>
</resources>
1 change: 1 addition & 0 deletions example/android/app/versions.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.versionCode=1
Loading

0 comments on commit 32d91dc

Please sign in to comment.