platforms_source_gen

A Flutter package gen platform's source code, include Android or iOS, Web ....

中文文档

Overview

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.

eg: Route Path

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:

in android:

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";
    //.......
}

in flutter:

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";
  //.......
}

and swift code or js file.....

this tools can help you only write dart code, platform's code will auto generation.

Quick Start

01 Step

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

02 Step

write your dart class file in flutter project path and format it, for example: ./lib/example :

Note: format is very import, it will fail if dart file no format.

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.

03 Step

write a main fun in ./test/any.dart and run:

Note: the any.dart is in test dir

import 'package:platforms_source_gen/platforms_source_gen.dart';

void main() {
 List<GenClassBean> genClassBeans =platforms_source_gen_init(
      "./lib/example", //you dart file path
      "com.siyehua.example", //your android's  java class package name
      "./Android_gen" //your android file save path
  );
  platforms_source_gent_start("com.siyehua.example", "./Android_gen", genClassBeans);
}

now, you can find the android file in your custom path ./Android_gen

Support

classsupport
class
abstract class(interface)
extends
implements
compose

Note: abstract class must not have any methods that have been implemented, property must not have any default value.


methodsupport
all

Note: support abstract method in abstract class, don't support method no in class.


TypesupportAndroidiOS
boolBoolean
intLong
doubleDouble
StringString
Uint8Listbyte[]
Int32Listint[]
Int64Listlong[]
Float64Listdouble[]
List< T >ArrayList<>
Map<T, U>HashMap<T, U>
var
dynamic
Object
Custom Class

Note: don't support List a= [];, because it's the same as List<dynamic> a =[];, , and dynamic is't support, Map is also like this.

FQA & BUG

  1. iOS is support?
    Yes, but this version only support Android, Welcome anybody push iOS support. Web or Desktop, and any other platform language.
  2. Why add package in dev_dependencies?
    because this tools only create platform language but not dart, so we don't need add it in dependencies.
  3. it's the same with source_gen or builder?
    the source_gen will create dart code, but this tools only create platform languages.

more questions or but, you can go to github

Libraries

android_gen
class_parse
example
example2
method_parse
platforms_source_gen
property_parse