A Flutter package gen platform's source code, include Android or iOS, Web ....
platforms_source_gen providers utilities from automated source code generation from Dart file.
When you build flutter as a Module in Android, iOS or other platform, you have to write some same function code.
When you dump to a android page, and then you dump to flutter page, and dump to android page...
you can use some package, like flutter_boost dump:
public class Route {
public static final String android_page1 = "/android/page1";
public static final String android_page2 = "/android/page2";
//.......
public static final String flutter_page1 = "/flutter/page1";
public static final String flutter_page2 = "/flutter/page2";
//.......
}
class Route {
static const String android_page1 = "/android/page1";
static const String android_page2 = "/android/page2";
//.......
static const String flutter_page1 = "/flutter/page1";
static const String flutter_page2 = "/flutter/page2";
//.......
}
@interface MQQFlutterGen_Route : NSObject
@property (nonatomic, strong) String *main_page;
@property (nonatomic, strong) String *mine_main;
@property (nonatomic, assign) int int_value;
@end
and Swift code or js code ... this tools can let you only write dart code, and auto generates other platform's code.
Add a dependency on platforms_source_gen
in your pubspec.yaml file and use dart pub get
down this package:
dev_dependencies:
platforms_source_gen: version
the versions click this, more installing info, you can see this
write your dart class file in flutter project path and format it, for example: ./lib/example
:
class InnerClass {
String a;
int b;
}
class Route {
static const String main_page = "/main/page"; //main page
static const String mine_main = "/mine/main"; //
static const int int_value = 123;
}
more example class, your can get it from github.
write a main fun in ./test/any.dart
and run:
import 'package:platforms_source_gen/platforms_source_gen.dart';
void main() async {
List<GenClassBean> genClassBeans = await platforms_source_gen_init(
"./lib/example", //you dart file path
);
platforms_source_gent_start(
"com.siyehua.example", //javaPackage
"./Android_gen", // androidSavePath
genClassBeans,
nullSafe: true);
platforms_source_start_gen_objc(
"MQQFlutterGen_", // iOS Pre
"./iOS_gen", //iOS save path
genClassBeans,
nullSafe: true);
}
now, you can find the android file in your custom path ./Android_gen
, or Objective-C file in ./iOS_gen
.
class | support |
---|---|
class | ✅ |
abstract class(interface) | ✅ |
extends | ❌ |
implements | ❌ |
compose | ✅ |
Note: abstract class
must not have any implemented methods, property must not have any default value.
method | support |
---|---|
all | ✅ |
Type | support | Android | iOS |
---|---|---|---|
bool | ✅ | Boolean | BOOL |
int | ✅ | Long | int |
double | ✅ | Double | double |
String | ✅ | String | NSString |
Uint8List | ✅ | byte[] | NSData |
Int32List | ✅ | int[] | NSData |
Int64List | ✅ | long[] | NSData |
Float64List | ✅ | double[] | NSData |
List< T > | ✅ | ArrayList<> | NSArray |
Map<T, U> | ✅ | HashMap<T, U> | NSDictionary |
var | ❌ | ||
dynamic | ❌ | ||
Object | ✅ | ❌ | id |
Custom Class | ✅ |
Note: Currently don't support List a= [];
, because it's the same as List<dynamic> a =[];
, , and dynamic
feature doesn't support, Map
is same.
- Why add package in dev_dependencies?
because this tool only use to create other platform language, so we don't need to add it in dependencies. - It's the same with source_gen or builder?
thesource_gen
will create dart code, but this tool create other platform codes.
For more questions, you can go to issues