tingyun_flutter_plugin 2.2.4 copy "tingyun_flutter_plugin: ^2.2.4" to clipboard
tingyun_flutter_plugin: ^2.2.4 copied to clipboard

The Tingyun Flutter plugin helps auto-instrument your Flutter app with Tingyun Agent for Android and iOS. It also provides an API to add manual instrumentation.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:tingyun_flutter_plugin/tingyun_flutter_plugin.dart';

void main() {
  // runApp(MyApp());
  Tingyun().start(MyApp(), onError: onCustomError, flutterOnError: onCustomFlutterError);
}

void onCustomError(Object object, StackTrace stackTrace){
  print('onCustomError happened');
}

void onCustomFlutterError(FlutterErrorDetails details){
  print('onCustomFlutterError happened');
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  static List<Uint8List> arraysByte = [];

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion = '';
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      // platformVersion = await TingyunFlutterPlugin.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          // new GestureDetector(
          //   onTap: (){
          //      print("gesture hope click")
          //   },
          //   child: Text('network'),
          // )

          child: new Column(children: <Widget>[
            Text(
              'Running on: $_platformVersion\n',
            ),
            createTag("network", (){
              print("network clicked");
            }),

            createTag("byte create", () {
              arraysByte.add(Uint8List(60*1024*1024));
            })
          ]),
        ),
      ),
    );
  }

  Widget createTag(String tagName, VoidCallback callback){
    return new TextButton(
          onPressed: callback,
          child: Text(tagName),
    );

    // return new GestureDetector(
    //   onTap: () {
    //     print("crete tag my title 11");
    //     throw StateError("This is a Dart exception");
    //     getHttpOrigin();
    //   },
    //   child: new TextButton(
    //     onPressed: callback,
    //     child: Text(tagName),
    //   ),
    // );
  }

  void getHttpOrigin() async{
    try{
      print("getHttpOrigin");

      await InternetAddress.lookup("www.baidu.com").then((value) {
        for(InternetAddress address in value){
          print("address:" + address.address);
        }
      });
      var url = 'https://www.baidu.com';
      HttpClientRequest clientRequest = await HttpClient().getUrl(Uri.parse(url));
      clientRequest.headers.add("aaa", "123456");

      HttpClientResponse response = await clientRequest.close();
      print("response body:" + response.toString());
      
      // await HttpClient()
      //     .getUrl(Uri.parse(url))
      //     .then((request) => request.close())//这个reqeust.close函数的原型 是 返回的respose,所以下面的then的参数是response了
      //     .then((response) => print("request done"));
    }catch(e, stacktrace){
      print("getHttpOrigin: runtimeType: ${e.runtimeType}, error:${e.toString()}");
      print("getHttpOrigin:${stacktrace}");

      //这里获取到的是127的行号
      print("1111111112222222:${StackTrace.current.toString()}");
    }
  }
}
0
likes
105
pub points
60%
popularity

Publisher

unverified uploader

The Tingyun Flutter plugin helps auto-instrument your Flutter app with Tingyun Agent for Android and iOS. It also provides an API to add manual instrumentation.

Homepage

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on tingyun_flutter_plugin