Skip to content

Instantly share code, notes, and snippets.

@kitsuniru
Last active July 2, 2023 22:01
Show Gist options
  • Save kitsuniru/536e07d3011fd7c4e3ce17559a1ed944 to your computer and use it in GitHub Desktop.
Save kitsuniru/536e07d3011fd7c4e3ce17559a1ed944 to your computer and use it in GitHub Desktop.
Memory leak demo via ListView without count + FadeTransition
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Memory Leak demo'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
late final anim = AnimationController(vsync: this);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
// There's no child to build, constraints equals to zero
// Item count is equal to infinite, so that means we have ((0;0) * infinite) pixels
// to paint on the screen, which bounds in our viewport contsraints
body: ListView.builder(itemBuilder: (context, i) => FadeTransition(opacity: anim))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment