cloudwise_flutter_plugin 2.7.3
cloudwise_flutter_plugin: ^2.7.3 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 'package:example/constant/TSBConst.dart';
import 'package:example/widget/CAppBar.dart';
import 'package:example/widget/CItemView.dart';
import 'crash/Crash.dart';
import 'crash/FlutterCrashPage.dart';
import 'custom/Custom.dart';
import 'custom/CustomEvent.dart';
import 'http/DioPage.dart';
import 'http/Http.dart';
import 'http/HttpClientPage.dart';
import 'image/ImagePage.dart';
import '/setting/Setting.dart';
import 'package:flutter/material.dart';
import 'h5/H5Page.dart';
import 'h5/WebviewPage.dart';
import 'package:cloudwise_flutter_plugin/src/cloudwise_flutter_plugin.dart';
main() async {
// 确保Flutter框架已初始化
WidgetsFlutterBinding.ensureInitialized();
// 获取存储的值,如果不存在则使用默认值
String _dataDomain = TSBConst.DATA_DOMAIN; //'http://10.0.7.115:18080';
String _appkey = TSBConst.APP_KEY; //'wS0n2SF8WRDB0iOsCaTCO**BpxQfmmgrWob0CMBn9yWvgEvIng2VudjApM3Dah7YP';
String _costomUserId = 'test_11';
String _costomVersion = '2.6.2';
String _costomDeviceId = 'cwsa_devece_id_1111';
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);
}
configuration.setStartOption(MonitorTypeWeb|MonitorTypeANR);
CloudwiseImpl().start(MyApp(), configuration: configuration);
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final List<Map<String, String>> items = [
{'title': 'HTTP Request', 'route': '/Http'},
{'title': 'Crash Page', 'route': '/Crash'},
{'title': 'Webview Page', 'route': '/H5Page'},
{'title': 'Custom Page', 'route': '/Custom'},
{'title': 'Image Page', 'route': '/ImagePage'},
];
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {
'/main': (context) => MainWeight(),
'/Http': (context) => Http(),
'/DioPage': (context) => DioPage(),
'/HttpClientPage': (context) => HttpClientPage(),
'/H5Page': (context) => H5Page(),
'/WebviewPage': (context, {arguments}) => WebViewExample(ModalRoute.of(context)?.settings.arguments),
'/Crash': (context) => Crash(),
'/FlutterCrashPage': (Context) => FlutterCrashPage(),
'/Custom': (context) => Custom(),
'/CustomEvent': (context) => CustomEvent(),
'/CustomUserInfo': (context) => CustomEvent(),
'/ImagePage': (context) => ImagePage()
},
onUnknownRoute: (RouteSettings settings) {
String? name = settings.name;
print("未匹配到路由:$name");
return null;
},
navigatorObservers: [
CloudwiseRouteObserver()
],
home: MainWeight(),
);
}
}
class MainWeight extends StatefulWidget {
@override
State<StatefulWidget> createState() => _MainWeightState();
}
class _MainWeightState extends State<MainWeight> {
int _currentIndex = 0;
final List<Widget> _pages = [MainPage(), SettingPage()];
@override
Widget build(BuildContext context) {
return Scaffold(
/*appBar: CAppBar(
text: "Cloudwise Plugin Demo",
isBack: false,
),*/
body: _pages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.list),
label: 'Function',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
),
);
}
}
class MainPage extends StatelessWidget {
final List<Map<String, String>> items = [
{'title': 'HTTP Request', 'route': '/Http'},
{'title': 'Crash Page', 'route': '/Crash'},
{'title': 'Webview Page', 'route': '/H5Page'},
{'title': 'Custom Page', 'route': '/Custom'},
{'title': 'Image Page', 'route': '/ImagePage'},
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CAppBar(
text: "Function",
isBack: false,
),
body: ListView.separated(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return ListBody(
children: [
CItemView(
height: 60,
viewType: ItemViewType.TYPE_JUMP_ARROW,
text: item['title']!,
onTap: (){
Navigator.of(context).pushNamed(item['route']!);
},
)
],
);
},
separatorBuilder: (context, index) => Divider(
height: 0,
color: Colors.transparent,
),
),
);
}
}