dsbridge_flutter 1.1.0 dsbridge_flutter: ^1.1.0 copied to clipboard
A modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and Dart.
import 'package:flutter/material.dart';
import 'js_call_dart_page.dart';
import 'dart_call_js_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const HomePage(),
theme: ThemeData(
useMaterial3: true,
),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('DSBridge for Flutter'),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
FilledButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DartCallJsPage()));
},
child: const Text('Dart call JavaScript'),
),
FilledButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const JsCallDartPage()));
},
child: const Text('JavaScript call Dart'),
),
],
),
),
);
}
}