leak_detector 0.1.0-bate copy "leak_detector: ^0.1.0-bate" to clipboard
leak_detector: ^0.1.0-bate copied to clipboard

outdated

flutter memory leak detector.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:leak_detector/leak_detector.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  GlobalKey<NavigatorState> _navigatorKey = GlobalKey();

  @override
  void initState() {
    super.initState();
    //must init the tools
    LeakDetector().init(maxRetainingPath: 300);
    LeakDetector().onLeakedStream.listen((LeakedInfo info) {
      showLeakedInfoPage(_navigatorKey.currentContext, info);
    });
    LeakDetector().onEventStream.listen((DetectorEvent event) {
      print(event);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: _navigatorKey,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              FlatButton(
                onPressed: () {
                  Navigator.of(_navigatorKey.currentContext).push(MaterialPageRoute(builder: (_) => TestLeakPage()));
                },
                color: Colors.blue,
                child: Text(
                  'jump',
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ),
              FlatButton(
                onPressed: () {
                  getLeakedRecording().then((List<LeakedInfo> list) {
                    showLeakedInfoListPage(_navigatorKey.currentContext, list);
                  });
                },
                color: Colors.blue,
                child: Text(
                  'read history',
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class TestLeakPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TestLeakPageState();
  }
}

class TestLeakPageState extends State with StateLeakMixin {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('leaked page'),
      ),
      body: Center(
        child: FlatButton(
          onPressed: () {
            //the 'context' is leaked
            Navigator.of(context).pop(context);
          },
          color: Colors.blue,
          child: Text(
            'pop',
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}
64
likes
0
points
117
downloads

Publisher

unverified uploader

Weekly Downloads

flutter memory leak detector.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path, sqflite, vm_service

More

Packages that depend on leak_detector