cloudwise_flutter_plugin 2.8.3
cloudwise_flutter_plugin: ^2.8.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/tsb_const.dart';
import 'package:example/widget/c_app_bar.dart';
import 'package:example/widget/c_item_view.dart';
import 'package:flutter/foundation.dart';
import 'crash/crash_page.dart';
import 'crash/flutter_crash_page.dart';
import 'custom/custom_page.dart';
import 'custom/custom_event.dart';
import 'http/dio_page.dart';
import 'http/http_page.dart';
import 'http/http_client_page.dart';
import 'image/image_page.dart';
import '/setting/setting_page.dart';
import 'package:flutter/material.dart';
import 'h5/h5_page.dart';
import 'h5/webview_page.dart';
import 'package:cloudwise_flutter_plugin/cloudwise_flutter_plugin.dart';
main() async {
// 确保Flutter框架已初始化
WidgetsFlutterBinding.ensureInitialized();
// 获取存储的值,如果不存在则使用默认值
String dataDomain = TSBConst.dataDomain;
String appKey = TSBConst.appKey;
String customUserId = 'test_11';
String customVersion = '2.8.2';
String customDeviceId = 'cloudWise_device_id_1111';
CloudwiseImpl().setCustomUserInfo(customUserId, {});
var configuration =
Configuration(isDebug: true, datadomain: dataDomain, appkey: appKey);
if (customVersion.isNotEmpty) {
configuration.setAppVersion(customVersion);
}
configuration.setSdkException(true);
if (customDeviceId.isNotEmpty) {
CloudwiseImpl().setCustomDeviceId(customDeviceId);
}
configuration
.setStartOption(monitorTypeUI | monitorTypeNetwork | monitorTypeCrash);
CloudwiseImpl().start(const MyApp(), configuration: configuration);
//runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@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) => const MainWeight(),
'/Http': (context) => const Http(),
'/DioPage': (context) => const DioPage(),
'/HttpClientPage': (context) => const HttpClientPage(),
'/H5Page': (context) => const H5Page(),
'/WebviewPage': (context, {arguments}) => WebViewExample(
ModalRoute.of(context)!.settings.arguments.toString()),
'/Crash': (context) => const Crash(),
'/FlutterCrashPage': (context) => const FlutterCrashPage(),
'/Custom': (context) => const Custom(),
'/CustomEvent': (context) => const CustomEvent(),
'/CustomUserInfo': (context) => const CustomEvent(),
'/ImagePage': (context) => const ImagePage()
},
onUnknownRoute: (RouteSettings settings) {
String? name = settings.name;
if (kDebugMode) {
print("未匹配到路由:$name");
}
return null;
},
navigatorObservers: [CloudwiseRouteObserver()],
home: const MainWeight(),
);
}
}
class MainWeight extends StatefulWidget {
const MainWeight({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _MainWeightState();
}
class _MainWeightState extends State<MainWeight> {
int _currentIndex = 0;
final List<Widget> _pages = [MainPage(), const 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: const [
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'},
];
MainPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const 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.typeJumpArrow,
text: item['title']!,
onTap: () {
Navigator.of(context).pushNamed(item['route']!);
},
)
],
);
},
separatorBuilder: (context, index) => const Divider(
height: 0,
color: Colors.transparent,
),
),
);
}
}