एक आधुनिक क्रॉस-प्लेटफ़ॉर्म जावास्क्रिप्ट ब्रिज, जिसके माध्यम से आप जावास्क्रिप्ट और डार्ट के बीच एक दूसरे के कार्यों को सिंक्रोनस या एसिंक्रोनस रूप से आह्वान कर सकते हैं।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
dsbridge_flutter एक क्रॉस-प्लेटफॉर्म जावास्क्रिप्ट ब्रिज है जो फ्लटर एप्लिकेशन में जावास्क्रिप्ट और डार्ट के बीच सहज, सिंक्रोनस या एसिंक्रोनस फंक्शन कॉल की अनुमति देता है। यह एंड्रॉइड, आईओएस और मैकओएस का समर्थन करता है, जिससे डेवलपर्स वेब कंटेंट को नेटिव फंक्शनलिटी के साथ एकीकृत कर सकते हैं। ब्रिज द्विदिश आदान-प्रदान को सुविधाजनक बनाता है, जिससे यह हाइब्रिड ऐप विकास के लिए आदर्श है जहां वेब व्यू नेटिव कोड से बातचीत करते हैं। इसका हल्का डिज़ाइन और सीधा API मौजूदा प्रोजेक्ट में एकीकरण को सरल बनाता है।
उपयोग
नेटिव फ्लटर सुविधाओं के साथ वेब दृश्यों का एकीकरण
वेब और Dart के बीच रियल-टाइम संचार सक्षम करना
वेब कंपोनेंट्स के साथ हाइब्रिड मोबाइल ऐप्स बनाना
कस्टम JavaScript से Dart कॉलबैक का अनुक्रमण
JavaScript के माध्यम से डायनामिक UI अपडेट का समर्थन करना
वेब-आधारित तर्क को Flutter व्यापार तर्क से जोड़ना
मुख्य विशेषताएँ
द्विदिश फ़ंक्शन कॉल
सिंक्रोनस और एसिंक्रोनस कॉल
क्रॉस-प्लेटफ़ॉर्म समर्थन (Android, iOS, macOS)
हल्का और आसानी से एकीकृत एपीआई
सुरक्षित संचार चैनल
जटिल डेटा प्रकारों का समर्थन करता है
इनके लिए उपयुक्त
हाइब्रिड ऐप विकासकर्ता
वेब व्यू एंटीग्रेटर
JavaScript का उपयोग करने वाले Flutter विकासकर्ता
टाइट वेब-नेटिव एकीकरण की आवश्यकता वाले ऐप्स
गतिशील, बातचीत वाले इंटरफेस बनाने वाली टीमें
वास्तविक समय डेटा आदान-प्रदान की आवश्यकता वाले परियोजनाएं
विचार योग्य बातें
JavaScript को Dart फ़ंक्शन प्रदर्शित करते समय सुरक्षा का ध्यानपूर्वक निर्देशन आवश्यक है
अविश्वसनीय जावास्क्रिप्ट इनपुट के लिए अतिरिक्त प्रमाणीकरण की आवश्यकता हो सकती है
उच्च आवृत्ति, कम प्रतिक्रिया समय ऑपरेशन के लिए उपयुक्त नहीं
परिपक्व पैकेज की तुलना में सीमित दस्तावेज़
बड़े डेटा स्थानांतरण के साथ संभावित प्रदर्शन अवरोध
मेमोरी लीक को रोकने के लिए ब्रिज के जीवनचक्र का प्रबंधन करना आवश्यक है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
DSBridge for Flutter
Modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and Flutter applications.
Dart APIs must be registered with registerFunction in register function.
Note that if you use the --obfuscate option to obfuscate Dart code when building your application, you need to annotate the function with @pragma('vm:entry-point') or use the second parameter functionName of registerFunction to specify the function name.
Namespaces can help you better manage your APIs, which is very useful in hybrid applications, because these applications have a large number of APIs. DSBridge allows you to classify API with namespace. The namespace can be multilevel, between different levels with '.' division.
Debug mode
In debug mode, some errors will be prompted by a popup dialog , and the exception caused by the dart APIs will not be captured to expose problems.
Progress Callback
Normally, when a API is called to end, it returns a result, which corresponds one by one. But sometimes a call need to repeatedly return multiple times, Suppose that on the Flutter side, there is a API to download the file, in the process of downloading, it will send the progress information to JavaScript many times, then JavaScript will display the progress information on the H5 page. Oh...You will find it is difficult to achieve this function. Fortunately, DSBridge supports Progress Callback. You can be very simple and convenient to implement a call that needs to be returned many times. Here's an example of a countdown:
In Dart
voidcallProgress(dynamic args, CompletionHandler handler) {
var i = 10;
final timer = Timer.periodic(constDuration(seconds: 1), (timer) {
if (i == 0) {
timer.cancel();
handler.complete(0);
} else {
handler.setProgressData(i--);
}
});
}
In JavaScript
dsBridge.call("callProgress", function (value) {
document.getElementById("progress").innerText = value
})
For the complete sample code, please refer to the example project.
JavaScript popup box
For JavaScript popup box functions (alert/confirm/prompt), DSBridge has implemented them all by default, if you want to custom them, set the corresponding callback in DWebViewController. The default dialog box implemented by DSBridge is modal. This will block the UI thread.
API Reference
Dart API
In Dart, the object that implements the JavaScript interfaces is called Dart API object.
Call the JavaScript API. If a handler is given, the JavaScript handler can respond. the handlerName can contain the namespace. The handler will be called in Dart main isolate.
Example:
_controller.callHandler('append', args: ["I", "love", "you"],
handler: (retValue) {
print(retValue.toString());
});
/// call with namespace 'syn', More details to see the Demo project
_controller.callHandler('syn.getInfo', handler: (retValue) {
print(retValue.toString());
});
DWebViewController.javaScriptCloseWindowListener
DWebViewController calls callback when JavaScript calls window.closeyou can provide a callback to add your handler.
Test whether the handler exist in Dart, the handlerName can contain the namespace.
type: optional["all"|"syn"|"asyn" ], default is "all".
dsBridge.hasNativeMethod('testAsyn')
//test namespace method
dsBridge.hasNativeMethod('test.testAsyn')
// test if exist a asynchronous function that named "testSyn"
dsBridge.hasNativeMethod('testSyn','asyn') //false
Finally
If you like DSBridge for Flutter, please click star/like to let more people know it, Thanks!