native_web 0.0.2 native_web: ^0.0.2 copied to clipboard
a project that provides native interaction with js
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:native_web/common/Global.dart';
import 'package:native_web/native_web.dart';
import 'package:native_web/repository/controller/redirect_controller.dart';
void main() {
Global.init().then((value) => runApp(const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
textTheme: const TextTheme(
bodySmall: TextStyle(fontSize: 16),
bodyLarge: TextStyle(fontSize: 18),
),
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
// home: const WebViewPage_InApp(),
home: const MyHomePage(),
// 注册路由表
// routes: <String, WidgetBuilder>{
// "webView": (context) => const WebViewPage_InApp(),
// },
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyAppState();
}
class _MyAppState extends State<MyHomePage> {
String _platformVersion = 'Unknown';
final _nativeWebPlugin = NativeWeb();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _nativeWebPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
void _incrementCounter() {
RedirectController(context)
.isRedirectOrNot(Global.appKey, deviceNum: Global.deviceNum);
// Navigator.pushNamed(context, "webView");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
// routes: <String, WidgetBuilder>{
// "webView": (context) => const WebViewPage_InApp(),
// },
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
),
);
}
}