flutter_traffic_stats_plus 1.0.6 copy "flutter_traffic_stats_plus: ^1.0.6" to clipboard
flutter_traffic_stats_plus: ^1.0.6 copied to clipboard

A Flutter package for collecting and displaying in-app traffic statistics.

flutter_traffic_stats #

A Flutter package for collecting and displaying in-app traffic statistics.

Features #

  • Track session traffic stats for requests and responses
  • Persist in-memory stats through a caller-provided local storage callback
  • Auto-report stats through a caller-provided upload callback
  • View traffic data with a built-in stats page and widget
  • Control stats collection and floating widget visibility in app

Installation #

Add the dependency in pubspec.yaml:

dependencies:
  flutter_traffic_stats: ^1.0.0

Then run:

flutter pub get

Usage #

Import the package:

import 'package:flutter_traffic_stats/flutter_traffic_stats_plus.dart';

Enable or disable traffic collection:

FlutterTrafficStats.setEnabled(true);
FlutterTrafficStats.setAppVersion('1.0.0+100');

Configure persistence and reporting:

FlutterTrafficStats.configurePersistence(
  TrafficStatsPersistenceConfig(
    // Default is 30 seconds, which balances write frequency and data loss.
    onPersist: (snapshot) async {
      await saveTrafficStatsToLocal(snapshot.toJson());
    },
  ),
);

FlutterTrafficStats.configureReporting(
  TrafficStatsReportingConfig(
    // Default is every 30 minutes, with at most 3 reports per day.
    onReport: (snapshot, context) async {
      await uploadTrafficStats(snapshot.toJson(), trigger: context.trigger.name);
      return true;
    },
    loadReportQuota: loadTrafficStatsReportQuota,
    saveReportQuota: saveTrafficStatsReportQuota,
  ),
);

Restore from local storage on app startup:

final json = await loadTrafficStatsFromLocal();
if (json != null) {
  FlutterTrafficStats.restoreFromJson(json);
}

Trigger one manual report, for example after login:

await FlutterTrafficStats.reportNow();

Open the built-in stats page:

Navigator.of(context).push(
  MaterialPageRoute<void>(
    builder: (_) => const TrafficStatsPage(),
  ),
);

Show the floating stats widget:

FlutterTrafficStats.showFloatingWidget(context);

Example #

See the example directory for a complete sample app.

0
likes
150
points
201
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for collecting and displaying in-app traffic statistics.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dio, flutter, url_launcher

More

Packages that depend on flutter_traffic_stats_plus