• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Dart
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter AOP framework. Now compatible with Flutter v3.10.5

Language: English | 中文简体

Beike_AspectD

This is a fork of AspectD.

Beike_AspectD is an aop framework for dart. AspectD has provide developers call/execute/inject grammer to manipulate the dart code. Besides that, Beike_AspectD also provides

  • ✅ Support add grammer to add function to classes.
  • ✅ Support field get grammer to exchange the field get call.
  • ✅ Support null-safety(null-safety/2.5.3 branch).
  • ✅ Support flutter web.

What can we use Beike_AspectD for?

Beike has used Beike_AspectD in many packages.

  • Event tracking.
  • Json to model.
  • Performance monitoring.
  • Flutter framework bug fixing.

Installation

1. Apply flutter_tools.patch.

cd ...path/to/flutter
git apply path-for-beike_aspectd-package/inner/flutter_tools.patch
rm bin/cache/flutter_tools.stamp

Next time when you build your project, flutter tools will build automatically.

2. Add Beike_AspectD to your yaml.

dependencies:
   beike_aspectd:
     git:
         url: https://github.com/LianjiaTech/Beike_AspectD.git
         ref: 3.10.5

3. Add aop_config.yaml to your flutter project.

Add a file named aop_config.yaml to your flutter project's root directory(the same directory as pubspec.yaml).

You can copy the file from the example of Beike_AspectD. The content of the file are as follow

flutter_tools_hook:
  - project_name: 'beike_aspectd'
    exec_path: 'bin/starter.snapshot'

Flutter_tools will check the file to find if Beike_AspectD is enabled. And it will get the starter.snapshot to process the dill file.

4. Write your hook file and import the file.

hook_example.dart(aop implementation)

import 'package:beike_aspectd/aspectd.dart';

@Aspect()
@pragma("vm:entry-point")
class CallDemo {
  @pragma("vm:entry-point")
  CallDemo();

 //实例方法
 @Call("package:example/main.dart", "_MyHomePageState",
     "-_incrementCounter")
 @pragma("vm:entry-point")
 void _incrementCounter4(PointCut pointcut) {
   print('call instance method2!');
   pointcut.proceed();
 }
}

As hook_example.dart is not used in your project, we should import it in the project, or it will be tree shaked while compiling.

For example, we can import the file in main.dart.

// ignore: unused_import
import 'package:example/hook_example.dart';

Tutorial

In addition to the 3 ways(call/execute/inject) to do AOP programming AspectD provide us, Beike_AspectD also provide add/field get manipulation.

add

Add a method to a class, support class name regex, support super class filter.

  @Add("package:.+\\.dart", ".*", isRegex: true)
  @pragma("vm:entry-point")
  dynamic getBasicInfo(PointCut pointCut) {
    return pointCut?.sourceInfos ?? {};
  }

Code above add getBasicInfo() method to all the classes, you can use your own regex and superCls parameter to filter classes. We can call the function using the following code.

    dynamic self = someinstance;
    Map info = self.getBasicInfo(PointCut.pointCut());

field get

Every callsites of the a field will be manipulated.

 @pragma("vm:entry-point")
 @FieldGet('package:example/main.dart', 'MyApp', 'field', false)
 static String exchange2(PointCut pointCut) {
    return 'Beike_Aspectd';
}

Suppose MyApp class has a property called field, by using the the above code, when calling the property field, it will always return string 'Beike_Aspectd'.

Compatibility

Currently Beike_Aspectd support flutter 1.22.4 ,2.2.2, 2.5.3, 2.10.4 and 3.0.0.

Q&A

  • How to know if my code is hooked successfully?
    1. First you need to download the dart-sdk and checkout to the corresponding revision of flutter. The revision of dart can be found at path_to_flutter/bin/cache/dart-sdk/revision.
    2. Run the following command.
    path_to_flutter/bin/cache/dart-sdk/bin/dart  path_to_dart/pkg/vm/bin/dump_kernel.dart path_to_your_project/.dart_tool/flutter_build/***/app.dill output_path/out.dill.txt
    1. Open output_path/out.dill.txt file, check if your code is hook.

Contact

If you have any question, please feel free to file a issue.

More Repositories

1

BELLE

BELLE: Be Everyone's Large Language model Engine(开源中文对话大模型)
HTML
7,841
star
2

bruno

An enterprise-class package of Flutter components for mobile applications. ( Bruno 是基于一整套设计体系的 Flutter 组件库。)
Dart
3,258
star
3

retrofit-spring-boot-starter

A spring-boot starter for retrofit, supports rapid integration and feature enhancements.(适用于retrofit的spring-boot-starter,支持快速集成和功能增强)
Java
1,762
star
4

keframe

Components that optimize Flutter fluency.(Flutter 流畅度优化的通用方案,轻松解决卡顿问题)
Dart
935
star
5

fee

灯塔开源文档地址
JavaScript
875
star
6

hetu

低代码平台, 可视化编辑器,单手打代码,解放你的双手
TypeScript
795
star
7

sosotest

sosotest自动化测试平台
Python
509
star
8

kob

中心化的作业调度系统,定义了任务调度模型,实现了任务调度的统一管理和监控。
Java
423
star
9

d18n

d18n is a data desensitization tool for RDBMS.
Go
162
star
10

gson-plugin

辅助 Gson 库的 gradle 插件,防止 Json 数据解析类型异常。
Groovy
151
star
11

ProgressLayout

A simple Android library about progress layout
Java
89
star
12

flutter_fdb_package

Flutter应用的调试工具,协助采集性能优化、设计走查、QA测试等数据问题 ,提供UI拾取、UI标尺、取色器、内存信息、FPS检测和展示页面代码等功能。
Dart
85
star
13

LJRouter

Objective-C
83
star
14

lightning

lightning is a tool for binlog parsing. It can generate original SQL or flashback SQL.
Go
74
star
15

ke-ve

一站式的可视化服务集成平台
JavaScript
58
star
16

bk_flutter_image

flutter image,降低内存使用
Dart
48
star
17

flutter_ui_auto_test

贝壳 flutter UI 自动化测试
Dart
47
star
18

json-diff

A tool for find difference between two json-string. Support JSON string depth comparison, support JSON array unordered comparison. (用于比较两个JSON字符串的工具,支持JSON字符串深度比较,支持无序数组比较)
Java
46
star
19

dgraph-sql

Java
40
star
20

athena

An open-source implementation of sequence-to-sequence based speech processing engine
C++
38
star
21

Snap

网页截图
JavaScript
34
star
22

kbms

一个轻量级c++网络框架
C++
31
star
23

UIC

User Information Center
Go
30
star
24

flutter_beike_engine

C++
25
star
25

bucky-core

bucky框架核心模块
JavaScript
14
star
26

cicada-ci

TypeScript
12
star
27

BKFlutterWebNativeBridge

Flutter Web和Flutter Mobile桥接。
Objective-C
9
star
28

benchmark

Objective-C
8
star
29

newsboy

web platform to manage api, support mock service and api test
JavaScript
8
star
30

ked

ked 是基于 Ke Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。
TypeScript
4
star
31

bucky-cli

bucky框架业务使用脚手架
JavaScript
3
star
32

Storm-Counter

Storm consumer command queue from Kafka, then parse and excute command to storage numbers into Hbase
Java
2
star
33

athena-model-zoo

Athena-model-zoo can provide a lot of kinds of pre-trained models to be used for others.
2
star
34

gson-plugin-sdk

gson-plugin依赖这个sdk
Java
1
star