Skip to content

Instantly share code, notes, and snippets.

@esDotDev
Last active August 10, 2023 05:56
Show Gist options
  • Save esDotDev/30b80a2b3ca7e20e85a1fe4e68b91ca5 to your computer and use it in GitHub Desktop.
Save esDotDev/30b80a2b3ca7e20e85a1fe4e68b91ca5 to your computer and use it in GitHub Desktop.

import 'package:flutter/material.dart';

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

class SomeWidget extends StatefulWidget { @override State createState() => SomeWidgetState(); }

class SomeWidgetState extends State { int count = 0;

void incrementCount() => setState(() => count++);

@override Widget build(BuildContext context) { return SomeWidgetView(controller: this); } }

class SomeWidgetView extends StatelessWidget { const SomeWidgetView({super.key, required this.controller});

final SomeWidgetState controller;

@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: TextButton( onPressed: controller.incrementCount, child: MyDeepChild(count: controller.count), ), ), ), ); } }

class MyDeepChild extends StatelessWidget { const MyDeepChild({super.key, required this.count}); final int count;

@override Widget build(BuildContext context) { return Text('$count'); } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment