Skip to content

Instantly share code, notes, and snippets.

@kdmatrosov
Last active May 20, 2020 15:42
Show Gist options
  • Save kdmatrosov/8741cccdbb1c07728524dba79f1140d0 to your computer and use it in GitHub Desktop.
Save kdmatrosov/8741cccdbb1c07728524dba79f1140d0 to your computer and use it in GitHub Desktop.

Revisions

  1. kdmatrosov revised this gist May 20, 2020. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion performance_example.dart
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,11 @@ class _ExampleState extends State<Example> {
    child: Column(
    children: [
    FlatButton(
    child: Text('Счетчик: $_counter'),
    color: Colors.blue,
    child: Text(
    'Счетчик: $_counter',
    style: TextStyle(color: Colors.white),
    ),
    onPressed: () {
    setState(() {
    _counter++;
    @@ -54,6 +58,7 @@ class _ExampleState extends State<Example> {

    class WeNeedItOnlyOnce extends StatelessWidget {
    const WeNeedItOnlyOnce();

    @override
    Widget build(BuildContext context) {
    print('WeNeedItOnlyOnce');
  2. kdmatrosov created this gist May 20, 2020.
    65 changes: 65 additions & 0 deletions performance_example.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    import 'package:flutter/material.dart';

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

    class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    home: Scaffold(
    body: Example(),
    ),
    );
    }
    }

    class Example extends StatefulWidget {
    @override
    _ExampleState createState() => _ExampleState();
    }

    class _ExampleState extends State<Example> {
    int _counter = 0;

    Widget _weNeedItOnlyOnce() {
    print('_weNeedItOnlyOnce');
    return Padding(
    padding: EdgeInsets.all(32),
    child: Text('Просто немного текста'),
    );
    }

    @override
    Widget build(BuildContext context) {
    return Padding(
    padding: EdgeInsets.all(32),
    child: Column(
    children: [
    FlatButton(
    child: Text('Счетчик: $_counter'),
    onPressed: () {
    setState(() {
    _counter++;
    });
    },
    ),
    _weNeedItOnlyOnce(),
    const WeNeedItOnlyOnce(),
    ],
    ));
    }
    }

    class WeNeedItOnlyOnce extends StatelessWidget {
    const WeNeedItOnlyOnce();
    @override
    Widget build(BuildContext context) {
    print('WeNeedItOnlyOnce');
    return Padding(
    padding: EdgeInsets.all(32),
    child: Text('Просто немного текста 2'),
    );
    }
    }