cloudwise_flutter_plugin 2.6.1 copy "cloudwise_flutter_plugin: ^2.6.1" to clipboard
cloudwise_flutter_plugin: ^2.6.1 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/SocketPage.dart';
import 'image/ImagePage.dart';
//import 'http/DioIsolatePage.dart';
import '/customInitInfos/CustomInitInfo.dart';
import '/setting/Setting.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);
  }

//  configuration.setSdkEncrypt(true);

  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请求', 'route': '/Http'},
    {'title': 'Crash崩溃', 'route': '/Crash'},
    {'title': 'H5请求', 'route': '/H5Page'},
    {'title': 'ANR', 'route': '/Anr'},
    {'title': 'SOCKET', 'route': '/SocketPage'},
    {'title': '自定义接口', 'route': '/Custom'},
    {'title': '加载图片', 'route': '/ImagePage'},
    {'title': '重置初始化信息', 'route': '/CustomInitInfo'},
  ];

  @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(),
        '/SocketPage': (context) => SocketPage(),
        '/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() => _MainWeightState();
}

class _MainWeightState extends State<MainWeight> {
  int _currentIndex = 0;

  final List<Widget> _pages = [MainPage(), SettingPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Cloudwise Plugin Demo'),
        centerTitle: true,
        backgroundColor: Colors.blue,
      ),
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.list),
            label: 'List',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            label: 'Settings',
          ),
        ],
      ),
    );
  }
}

class MainPage extends StatelessWidget {
  final List<Map<String, String>> items = [
    {'title': 'HTTP请求', 'route': '/Http'},
    {'title': 'Crash崩溃', 'route': '/Crash'},
    {'title': 'H5请求', 'route': '/H5Page'},
    {'title': 'ANR', 'route': '/Anr'},
    {'title': 'SOCKET', 'route': '/SocketPage'},
    {'title': '自定义接口', 'route': '/Custom'},
    {'title': '加载图片', 'route': '/ImagePage'},
    {'title': '重置初始化信息', 'route': '/CustomInitInfo'},
  ];

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: items.length,
      itemBuilder: (context, index) {
        final item = items[index];
        return ListTile(
          title: Text(item['title']!),
          onTap: () {
            Navigator.of(context).pushNamed(item['route']!);
          },
        );
      },
      separatorBuilder: (context, index) => Divider(),
    );
  }
}
7
likes
0
points
121
downloads

Publisher

unverified uploader

Weekly Downloads

This is the official flutter plugin for Cloudwise,with this plugin you can easily collect your app data on Android and iOS.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on cloudwise_flutter_plugin

Packages that implement cloudwise_flutter_plugin