yc_plugin_learn 1.0.5
yc_plugin_learn: ^1.0.5 copied to clipboard
演示项目:flutter项目嵌入原生代码、嵌入原生view,双方交互事件,在原生插件中使用第三方工具,
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:yc_plugin_learn/base/abstract/IFFScaffold.dart';
import 'package:yc_plugin_learn/base/demos/Start.dart';
import 'package:yc_plugin_learn/yc_plugin_learn.dart';
import 'package:yc_plugin_learn_example/TestView.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
/**
* 本插件项目主要演示以下几个方面,主要用于教学使用
* 1。flutter与原生互相传递事件信息
* 2。在原生项目中使用第三方包glide加载图片,主要用于演示如何在插件中使用第三方包
* 3。flutter页面上嵌入原生view,并实现独立的事件互传
* 4。如何在插件代码里获取当前Context
* 5。插件开发中Android代码报红的解决
*
*/
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
/********************注意,下面的代码用来演示插件的用法 */
// void main() {
// runApp(const MyApp());
// }
// class MyApp extends StatefulWidget {
// const MyApp({Key? key}) : super(key: key);
// @override
// State<MyApp> createState() => _MyAppState();
// }
// class _MyAppState extends State<MyApp>
// implements YcPluginCallBack /* 实现插件接口,用于接收原生主动发送的消息 */ {
// String _platformVersion = 'Unknown';
// var _data = null;
// double width = 300;
// @override
// void initState() {
// super.initState();
// initPlatformState();
// initData();
// //初始化
// YcPluginLearn.init(appId: "appId").then((value) {
// print("flutter init ${value}");
// //测试,打开便可看到控制台疯狂的输出来自原生的回调
// //YcPluginLearn.test();
// });
// //设置回调
// YcPluginLearn.ycPluginCallBack = this;
// }
// Future<void> initPlatformState() async {
// String platformVersion;
// try {
// platformVersion =
// await YcPluginLearn.platformVersion ?? 'Unknown platform version';
// } on PlatformException {
// platformVersion = 'Failed to get platform version.';
// }
// if (!mounted) return;
// setState(() {
// _platformVersion = platformVersion;
// });
// }
// //加载图片数据
// initData() async {
// _data = await YcPluginLearn.getImage(
// "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F052420110515%2F200524110515-2-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653472637&t=0a02c0594866f17f15d29a4753161f6e");
// setState(() {});
// }
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// home: Scaffold(
// appBar: AppBar(
// title: const Text('Plugin example app'),
// ),
// body: Center(
// child: Column(
// children: [
// Text('Running on: $_platformVersion\n'),
// _data == null
// ? Container(
// color: Colors.grey,
// width: 100,
// height: 100,
// )
// : Image.memory(
// _data,
// width: 100,
// height: 100,
// fit: BoxFit.cover,
// ),
// GestureDetector(
// onTap: () {
// print("点我了");
// width += 5;
// setState(() {});
// },
// child: Container(
// height: 40,
// child: Text("点我刷新页面宽度"),
// color: Colors.blue,
// ),
// ),
// ///用来加载原生view
// TestView(
// width: width,
// ),
// Container(
// height: 20,
// ),
// ///另一个相同的组件
// TestView(
// width: width,
// ),
// ],
// ),
// ),
// ),
// );
// }
// @override
// void minuteCallBack(String minute) {
// // TODO: implement minuteCallBack
// print("minuteCallBack minute = ${minute}");
// }
// @override
// void secondCallBack(String second) {
// // TODO: implement secondCallBack
// print("secondCallBack second = ${second}");
// }
// @override
// void appListCallBack(list) {
// // TODO: implement appListCallBack
// }
// }
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**************注意,下面的代码用来展示封装的组件用的 */
/**设置主导航栈的key */
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
void main() {
// 绑定引擎
WidgetsFlutterBinding.ensureInitialized();
//沉浸状态栏
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
),
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
// return refreshConfig(context, app(context));
return app(context);
}
Widget app(BuildContext context) {
return MaterialApp(
title: '演示项目',
theme: ThemeData(
primarySwatch: Colors.blue,
),
navigatorObservers: [routeObserver],
home: Start(),
localizationsDelegates: [
RefreshLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('zh'),
],
locale: const Locale('zh'),
localeResolutionCallback:
(Locale? locale, Iterable<Locale>? supportedLocales) {
//print("change language");
return locale;
},
);
}
}