Skip to content

Commit acf700c

Browse files
Initial Commit for PlaformChannel Sample App (#453)
1 parent 8fbe1d6 commit acf700c

File tree

67 files changed

+1805
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1805
-0
lines changed

platform_channels/.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
/build/
32+
33+
# Web related
34+
lib/generated_plugin_registrant.dart
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Exceptions to above rules.
43+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

platform_channels/.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 5f21edf8b66e31a39133177319414395cc5b5f48
8+
channel: stable
9+
10+
project_type: app

platform_channels/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Platform Channel Samples
2+
3+
A sample app which demonstrates how to use `MethodChannel`, `EventChannel`, `BasicMessageChannel` and `MessageCodec` in Flutter.
4+
5+
This sample is currently being built. Not all platforms and functionality are in place.
6+
7+
## Goals
8+
9+
* Demonstrate how to use `MethodChannel` to invoke platform methods.
10+
* Demonstrate how to use `EventChannel` to listen continuous value changes from the platform.
11+
* Demonstrate how to use `BasicMessageChanngel` and `MessageCodec` to send messages of different types across the platform.
12+
13+
## Questions/issues
14+
15+
If you have a general question about Platform Channels in Flutter, the
16+
best places to go are:
17+
18+
* [The FlutterDev Google Group](https://groups.google.com/forum/#!forum/flutter-dev)
19+
* [The Flutter Gitter channel](https://gitter.im/flutter/flutter)
20+
* [StackOverflow](https://stackoverflow.com/questions/tagged/flutter)
21+
22+
If you run into an issue with the sample itself, please file an issue [here](https://github.com/flutter/samples/issues).
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
include: package:pedantic/analysis_options.yaml
2+
3+
analyzer:
4+
strong-mode:
5+
implicit-casts: false
6+
implicit-dynamic: false
7+
8+
linter:
9+
rules:
10+
- avoid_types_on_closure_parameters
11+
- avoid_void_async
12+
- await_only_futures
13+
- camel_case_types
14+
- cancel_subscriptions
15+
- close_sinks
16+
- constant_identifier_names
17+
- control_flow_in_finally
18+
- directives_ordering
19+
- empty_statements
20+
- hash_and_equals
21+
- implementation_imports
22+
- non_constant_identifier_names
23+
- package_api_docs
24+
- package_names
25+
- package_prefixed_library_names
26+
- test_types_in_equals
27+
- throw_in_finally
28+
- unnecessary_brace_in_string_interps
29+
- unnecessary_getters_setters
30+
- unnecessary_new
31+
- unnecessary_statements

platform_channels/android/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
compileSdkVersion 28
30+
31+
sourceSets {
32+
main.java.srcDirs += 'src/main/kotlin'
33+
}
34+
35+
lintOptions {
36+
disable 'InvalidPackage'
37+
}
38+
39+
defaultConfig {
40+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41+
applicationId "com.example.platform_channels"
42+
minSdkVersion 16
43+
targetSdkVersion 28
44+
versionCode flutterVersionCode.toInteger()
45+
versionName flutterVersionName
46+
}
47+
48+
buildTypes {
49+
release {
50+
// TODO: Add your own signing config for the release build.
51+
// Signing with the debug keys for now, so `flutter run --release` works.
52+
signingConfig signingConfigs.debug
53+
}
54+
}
55+
}
56+
57+
flutter {
58+
source '../..'
59+
}
60+
61+
dependencies {
62+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
63+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="dev.flutter.platform_channels">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="dev.flutter.platform_channels">
3+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
4+
calls FlutterMain.startInitialization(this); in its onCreate method.
5+
In most cases you can leave this as-is, but you if you want to provide
6+
additional functionality it is fine to subclass or reimplement
7+
FlutterApplication and put your custom class here. -->
8+
<application
9+
android:name="io.flutter.app.FlutterApplication"
10+
android:label="platform_channels"
11+
android:icon="@mipmap/ic_launcher">
12+
<activity
13+
android:name=".MainActivity"
14+
android:launchMode="singleTop"
15+
android:theme="@style/LaunchTheme"
16+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
17+
android:hardwareAccelerated="true"
18+
android:windowSoftInputMode="adjustResize">
19+
<!-- Specifies an Android theme to apply to this Activity as soon as
20+
the Android process has started. This theme is visible to the user
21+
while the Flutter UI initializes. After that, this theme continues
22+
to determine the Window background behind the Flutter UI. -->
23+
<meta-data
24+
android:name="io.flutter.embedding.android.NormalTheme"
25+
android:resource="@style/NormalTheme"
26+
/>
27+
<!-- Displays an Android View that continues showing the launch screen
28+
Drawable until Flutter paints its first frame, then this splash
29+
screen fades out. A splash screen is useful to avoid any visual
30+
gap between the end of Android's launch screen and the painting of
31+
Flutter's first frame. -->
32+
<meta-data
33+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
34+
android:resource="@drawable/launch_background"
35+
/>
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN"/>
38+
<category android:name="android.intent.category.LAUNCHER"/>
39+
</intent-filter>
40+
</activity>
41+
<!-- Don't delete the meta-data below.
42+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
43+
<meta-data
44+
android:name="flutterEmbedding"
45+
android:value="2" />
46+
</application>
47+
</manifest>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.flutter.platform_channels
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
import io.flutter.embedding.engine.FlutterEngine
5+
import io.flutter.plugin.common.MethodChannel
6+
7+
class MainActivity : FlutterActivity() {
8+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
9+
// Creates a MethodChannel as soon as the FlutterEngine is attached to
10+
// the Activity, and registers a MethodCallHandler. The Method.setMethodCallHandler
11+
// is responsible to register a MethodCallHandler to handle the incoming calls.
12+
13+
// The call parameter of MethodCallHandler has information about the incoming call,
14+
// like method name, and arguments. The result parameter of MethodCallHandler is
15+
// responsible to send the results of the call.
16+
MethodChannel(flutterEngine.dartExecutor, "methodChannelDemo")
17+
.setMethodCallHandler { call, result ->
18+
val count: Int? = call.argument<Int>("count")
19+
20+
if (count == null) {
21+
result.error("INVALID ARGUMENT", "Value of count cannot be null", null)
22+
} else {
23+
when (call.method) {
24+
"increment" -> result.success(count + 1)
25+
"decrement" -> result.success(count - 1)
26+
else -> result.notImplemented()
27+
}
28+
}
29+
}
30+
}
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>

0 commit comments

Comments
 (0)