{"id":24650875,"url":"https://github.com/ggdream/call","last_synced_at":"2025-10-07T10:30:24.799Z","repository":{"id":56826948,"uuid":"345002085","full_name":"ggdream/call","owner":"ggdream","description":"Flutter: Calling dynamic link library defined in the assets field of pubsepc.yaml file. (Support Windows, Linux and MacOS)","archived":false,"fork":false,"pushed_at":"2021-03-19T04:32:23.000Z","size":61,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-08-20T21:30:41.056Z","etag":null,"topics":["call","cross-platform","dart","dylib","ffi","flutter","linux","macos","native","windows"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/call","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ggdream.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-06T04:10:32.000Z","updated_at":"2023-03-09T08:21:45.000Z","dependencies_parsed_at":"2022-09-13T08:00:43.173Z","dependency_job_id":null,"html_url":"https://github.com/ggdream/call","commit_stats":null,"previous_names":[],"tags_count":8,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ggdream%2Fcall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ggdream","download_url":"https://codeload.github.com/ggdream/call/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235614247,"owners_count":19018405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["call","cross-platform","dart","dylib","ffi","flutter","linux","macos","native","windows"],"created_at":"2025-01-25T18:16:53.624Z","updated_at":"2025-10-07T10:30:24.435Z","avatar_url":"https://github.com/ggdream.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# call\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://space.bilibili.com/264346349\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/bilibili-魔咔啦咔-blueviolet\" alt=\"😭\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/ggdream/call\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/GitHub-魔咔啦咔-ff69b4\" alt=\"😭\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Platforms-Windows,Linux,MacOS-009688\" alt=\"😭\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Mode-Debug,Release-3949ab\" alt=\"😭\" /\u003e\n\u003c/div\u003e\n\nYou can use the package to open the dylib defined in the `assets` field of `pubsepc.yaml`.\n\u003cbr/\u003e\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\n## 1.Prepare your dynamic link library\n- Write your C-code\n```c\n// file: ${PROJECT_ROOT}/assets/main.c\n\nint add(int a, int b) {\n  return a + b;\n}\n```\n\n- Compile it to a dylib\n```sh\ngcc -shared -fPIC -o libadd.so main.c           # Linux\ngcc -shared -fPIC -o libadd.dll main.c          # Windows\nclang -shared -fPIC -o libadd.dylib main.c      # MacOS\n\n# file: ${PROJECT_ROOT}/assets/libadd.dll\n```\n\n## 2. Declare the assets path\nYou should declare path of the dylib in the `pubspec.yaml` file as images.\n~~~yaml\nflutter:\n  assets:\n    - assets/libadd.dll # Fill it in according to your storage location\n~~~\n\n## 3. Write flutter core code to call native function.\n~~~dart\nimport 'package:flutter/material.dart';\n\nimport 'dart:ffi' as ffi;\nimport 'package:call/call.dart';\n\ntypedef FuncNative = ffi.Int32 Function(ffi.Int32, ffi.Int32);\ntypedef FuncDart = int Function(int, int);\n\n\n\nvoid main() =\u003e runApp(App());\n\nclass App extends StatefulWidget {\n  @override\n  _AppState createState() =\u003e _AppState();\n}\n\nclass _AppState extends State\u003cApp\u003e {\n  @override\n  Widget build(BuildContext context) {\n    var dll = getDyLibModule('assets/libadd.dll');     // use it as images.\n    var add = dll.lookupFunction\u003cFuncNative, FuncDart\u003e('add');\n\n    return Text(\n             add(999, 54639).toString(),\n             textDirection: TextDirection.ltr\n          );\n  }\n}\n~~~\n\n## 4. Run the flutter application\n\nFinally, You can see the number `55638` in the top left corner of the application.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggdream%2Fcall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fggdream%2Fcall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fggdream%2Fcall/lists"}