cloudwise_flutter_plugin 2.2.0
cloudwise_flutter_plugin: ^2.2.0 copied to clipboard
This is the official flutter plugin for Cloudwise,with this plugin you can easily collect your app data on Android and iOS.
example/lib/main.dart
import 'anr/Anr.dart';
import 'crash/Crash.dart';
import 'crash/JavaCrashPage.dart';
import 'custom/Custom.dart';
import 'custom/CustomEvent.dart';
import 'custom/CustomDeviceInfo.dart';
import 'custom/CustomAppVersion.dart';
import 'h5/H5DetailPage.dart';
import 'http/DioPage.dart';
import 'http/Http.dart';
import 'http/HttpClientPage.dart';
import 'socket/Socket.dart';
import 'image/ImagePage.dart';
import 'http/DioIsolatePage.dart';
import '/customInitInfos/CustomInitInfo.dart';
import 'package:flutter/material.dart';
import 'h5/H5Page.dart';
import 'h5/WebviewPage.dart';
import 'http/HttpPage.dart';
import 'http/IsolatePage.dart';
import 'package:cloudwise_flutter_plugin/src/cloudwise_flutter_plugin.dart';
import 'package:shared_preferences/shared_preferences.dart';
main() async {
// 确保Flutter框架已初始化
WidgetsFlutterBinding.ensureInitialized();
// 异步获取SharedPreferences实例
final prefs = await SharedPreferences.getInstance();
// 获取存储的值,如果不存在则使用默认值
String _dataDomain = prefs.getString('cwsa_dataDomain') ?? 'http://10.0.12.192:18080';
String _appkey = prefs.getString('cwsa_appkey') ?? 'wS0n2SF8WRDB0iOsCaTCO**BpxQfmmgrW/MTvIvJDHL0xffQl0iWFqhNF4JaTh5yN';
String _costomUserId = prefs.getString('cwsa_custom_userId') ?? '';
String _costomVersion = prefs.getString('cwsa_custom_version') ?? '';
String _costomDeviceId = prefs.getString('cwsa_custom_device_id') ?? '';
CloudwiseImpl().setCustomUserInfo(_costomUserId, Map());
var configuration = Configuration(
isDebug: true,
datadomain: _dataDomain,
appkey: _appkey
);
if(!_costomVersion.isEmpty){
configuration.setAppVersion(_costomVersion);
}
if(!_costomVersion.isEmpty){
CloudwiseImpl().setCustomDeviceId(_costomDeviceId);
}
CloudwiseImpl().start(MyApp(), configuration: configuration);
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/main': (context) => MainWeight(),
'/Http': (context) => Http(),
'/DioPage': (context) => DioPage(),
'/HttpClientPage': (context) => HttpClientPage(),
'/HttpPage': (context) => HttpPage(),
'/IsolatePage': (context) => IsolatePage(),
'/H5Page': (context) => H5Page(),
'/WebviewPage': (context,{arguments}) => WebViewExample(ModalRoute.of(context)?.settings.arguments),
'/DioIsolatePage': (context) => DioIsolatePage(),
'/H5DetailPage': (context, {arguments}) => H5DetailPage(ModalRoute.of(context)?.settings.arguments),
'/Crash': (context) => Crash(),
'/JavaCrashPage': (context) => JavaCrashPage(),
'/Anr': (context) => Anr(),
'/Socket': (context) => MSocket(),
'/Custom': (context) => Custom(),
'/CustomEvent': (context) => CustomEvent(),
'/CustomAPPVersion': (context) => CustomAppVersion(),
'/CustomDevieId': (context) => CustomDevicePage(),
'/CustomUserInfo': (context) => CustomEvent(),
'/ImagePage': (context) => ImagePage(),
'/CustomInitInfo': (context) => CustomInitInfosPage()
},
onUnknownRoute: (RouteSettings settings) {
String? name = settings.name;
print("未匹配到路由:$name");
return null;
},
navigatorObservers: [
CloudwiseRouteObserver()
],
home: MainWeight());
}
}
class MainWeight extends StatefulWidget {
@override
State<StatefulWidget> createState() => _mainWeight();
}
class _mainWeight extends State<MainWeight>{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cloudwise Flutter Demo'), centerTitle: true),
body: Container(
width: double.infinity,
child: Column(
children: [
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/Http');
},
child: Text(
"HTTP请求",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/Crash');
},
child: Text(
"Crash崩溃",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/H5Page');
},
child: Text(
"H5请求",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/Anr');
},
child: Text(
"ANR",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/Socket');
},
child: Text(
"SOCKET",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/Custom');
},
child: Text(
"自定义接口",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/ImagePage');
},
child: Text(
"加载图片",
style: TextStyle(fontSize: 20),
),
),
new TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/CustomInitInfo');
},
child: Text(
"重置初始化信息",
style: TextStyle(fontSize: 20),
),
),
],
),
));
}
}