This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object getInput() { | |
final dynamic input = []; | |
return input..add(2)..add(4)..add(55); | |
} | |
void main() async { | |
final List<int> result = getInput() as List<int>; // fail with `CastError: type 'List<dynamic>' is not a subtype of type 'List<int>'` | |
print(result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object getInput() { | |
final dynamic input = []; | |
return input..add(2)..add(4)..add(55); | |
} | |
void main() async { | |
final List<int> result = (getInput() as List<dynamic>).cast<int>(); | |
print(result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
String name; | |
List<UsaAddress> addresses; | |
List<Person> supervisorOf; | |
} | |
class UsaAddress { | |
String streetNameAndNumber; // nevermind validation | |
String streetNameAndNumber2; // nevermind validation | |
String city; // nevermind validation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// protoc --dart_out=./lib/gen ./protos/person.proto | |
// protoc --swift_out=./ios/gen ./protos/person.proto | |
syntax = "proto3"; | |
// `java_package` should match the package name you declare for `androidPackage` in your pubspec.yaml | |
option java_package = "pro.truongsinh.flutter.example.plugin_with_protobuf";; | |
message Person { | |
string name = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pubspec.yaml b/pubspec.yaml | |
index 207089d..c069c82 100644 | |
--- a/pubspec.yaml | |
+++ b/pubspec.yaml | |
@@ -8,6 +8,7 @@ environment: | |
sdk: ">=2.1.0 <3.0.0" | |
dependencies: | |
+ protobuf: any | |
flutter: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ios/plugin_with_protobuf.podspec b/ios/plugin_with_protobuf.podspec | |
index 8b0c4dc..ba34356 100644 | |
--- a/ios/plugin_with_protobuf.podspec | |
+++ b/ios/plugin_with_protobuf.podspec | |
@@ -15,7 +15,8 @@ A new flutter plugin project. | |
s.source_files = 'Classes/**/*' | |
s.public_header_files = 'Classes/**/*.h' | |
s.dependency 'Flutter' | |
+ s.dependency 'SwiftProtobuf', '~> 1.4' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ios/Classes/SwiftPluginWithProtobufPlugin.swift b/ios/Classes/SwiftPluginWithProtobufPlugin.swift | |
index e73d064..edbded6 100644 | |
--- a/ios/Classes/SwiftPluginWithProtobufPlugin.swift | |
+++ b/ios/Classes/SwiftPluginWithProtobufPlugin.swift | |
@@ -1,6 +1,49 @@ | |
import Flutter | |
import UIKit | |
+func getMyPerson() -> Person { | |
+ // abbr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/plugin_with_protobuf.dart b/lib/plugin_with_protobuf.dart | |
index 87a1759..a59870f 100644 | |
--- a/lib/plugin_with_protobuf.dart | |
+++ b/lib/plugin_with_protobuf.dart | |
@@ -1,13 +1,17 @@ | |
-import 'dart:async'; | |
+import 'dart:typed_data' show Uint8List; | |
-import 'package:flutter/services.dart'; | |
+import 'package:flutter/services.dart' show MethodChannel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/android/build.gradle b/android/build.gradle | |
index b0b0b97..d5c5c82 100644 | |
--- a/android/build.gradle | |
+++ b/android/build.gradle | |
@@ -3,6 +3,7 @@ version '1.0-SNAPSHOT' | |
buildscript { | |
ext.kotlin_version = '1.2.71' | |
+ ext.protobufVersion = '0.8.8' | |
repositories { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/android/src/main/kotlin/com/example/plugin_with_protobuf/PluginWithProtobufPlugin.kt b/android/src/main/kotlin/com/example/plugin_with_protobuf/PluginWithProtobufPlugin.kt | |
index 430bbe0..0969560 100644 | |
--- a/android/src/main/kotlin/com/example/plugin_with_protobuf/PluginWithProtobufPlugin.kt | |
+++ b/android/src/main/kotlin/com/example/plugin_with_protobuf/PluginWithProtobufPlugin.kt | |
@@ -6,6 +6,48 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler | |
import io.flutter.plugin.common.MethodChannel.Result | |
import io.flutter.plugin.common.PluginRegistry.Registrar | |
+fun getMyPerson(): PersonOuterClass.Person { | |
+ return PersonOuterClass.Person.newBuilder() |