finotescore 7.0.0 copy "finotescore: ^7.0.0" to clipboard
finotescore: ^7.0.0 copied to clipboard

Detect and report bugs in Flutter based mobile apps. Reports issues like memory leaks, crashes, ANR and exceptions. Plugin has low memory and size footprint.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
import 'dart:developer';

import 'package:finotescore/finotescore.dart';
import 'package:finotescore/fn_client.dart';
import 'package:finotescore/state_custom.dart';
import 'package:finotescore/fn_interceptor.dart';
import 'package:finotescore/observe.dart';
import 'package:flutter/material.dart';
import 'package:http_interceptor/http_interceptor.dart';

import 'package:http/http.dart' as http;

void main() {
  runApp(const MyRootApp());

  WidgetsFlutterBinding
      .ensureInitialized(); //Make sure to execute 'ensureInitialized' before executing Fn.init().
  Fn.logMe();
  Fn.init(); //Need to call this function to activate plugin.
  Observe().setMaskedHeaders(["connection"]);
  Observe().setWhiteListedDomain(["jsonplaceholder.typicode.com"]);
  Observe().setBaseUrlTimeouts({
    "jsonplaceholder.typicode.com": 1000
  }); //Timeout value(s) should be greater than or equal to 1000.
}

class MyRootApp extends StatelessWidget {
  const MyRootApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyScreenApp(),
    );
  }
}

class MyScreenApp extends StatefulWidget {
  const MyScreenApp({Key? key}) : super(key: key);

  @override
  State<MyScreenApp> createState() => _MyAppState();
}

class _MyAppState extends FnState<MyScreenApp> {
  //Replace 'State' class with 'FnState' to allow finotescore plugin to track lifecycle methods.
  int _counter = 0;

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

  void fetchTodoWithHttpClient() async {
    var client = FnClient(); //Replace your http client with finotescore client.
    try {
      var response = await client
          .get(Uri.https('jsonplaceholder.typicode.com', 'todos/1'));
      var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
      print(decodedResponse);
    } finally {
      client.close();
    }
  }

  void fetchTodoWithInterceptor() async {
    http.Client client = InterceptedClient.build(interceptors: [
      FnInterceptor(), //Add finotescore interceptor to track api calls.
    ]);
    try {
      final response = await client
          .get("https://jsonplaceholder.typicode.com/toos/1/".toUri());
      if (response.statusCode == 200) {
        log("API response ${json.decode(response.body)}");
      } else {
        throw Exception("Error while fetching. \n ${response.body}");
      }
    } catch (e) {
      print(e);
    }
  }

  void _incrementCounter(BuildContext context) {
    fetchTodoWithInterceptor();

    setState(() {
      _counter++;
    });
    Fn.setActivityMarkerAt("Main",
        "User tapped on increment counter"); //Set actvivity markers to get context on issues.

    runZonedGuarded(() async {
      throw Exception(); //Line with exception.
    }, (error, stackTrace) {
      Fn.reportError(
          error, stackTrace); //Single line API to report guarded errors.
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: Center(
        child: Text('Run $_counter'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _incrementCounter(context);
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
0
likes
130
pub points
10%
popularity

Publisher

unverified uploader

Detect and report bugs in Flutter based mobile apps. Reports issues like memory leaks, crashes, ANR and exceptions. Plugin has low memory and size footprint.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

crypto, device_info_plus, flutter, http, http_interceptor, stack_trace, uuid

More

Packages that depend on finotescore