js_import 1.0.2 copy "js_import: ^1.0.2" to clipboard
js_import: ^1.0.2 copied to clipboard

Importing JS libraries and injection JS scripts into Flutter Web projects.

example/lib/main.dart

import 'package:js_import/js_import.dart';
import 'package:flutter/material.dart';
import 'package:js/js_util.dart' as js_util;

void main() {
  JSImport.import(
    sources: [
      "asset/app.js",
    ],
  );
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text("JS Import"),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                "Is imported: ${JSImport.isImported(source: "asset/app.js")}",
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: () => js_util.callMethod(js_util.globalThis,
                    'alertMessage', ['Flutter is calling upon JavaScript!']),
                child: const Text(
                  "Alert",
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
150
pub points
29%
popularity

Publisher

unverified uploader

Importing JS libraries and injection JS scripts into Flutter Web projects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on js_import