Skip to content

Instantly share code, notes, and snippets.

@esDotDev
Last active August 10, 2023 15:49
Show Gist options
  • Save esDotDev/7f3586efc8ae89f3ec27356260ea71f3 to your computer and use it in GitHub Desktop.
Save esDotDev/7f3586efc8ae89f3ec27356260ea71f3 to your computer and use it in GitHub Desktop.
flying-neutron-5516
mport '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