Created
October 13, 2025 06:35
-
-
Save rena2019/d50ab71b15e46d4ec46cdd068692f8e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Flutter ValueNotifier + ValueListenableBuilder (reactive way to manage state) | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| //int progress = 50; | |
| final ValueNotifier<int> progress = ValueNotifier<int>(50); | |
| String status = "MY STATUS"; | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold(body: | |
| Column(children: | |
| [ | |
| ValueListenableBuilder<int>( | |
| valueListenable: progress, | |
| builder: (context, value, child) { | |
| return | |
| Text('status: ${status}, progress: ${progress.value}'); | |
| }), | |
| GestureDetector(onTap: () => { progress.value += 1 }, | |
| child: Text("CLICK")) | |
| ] | |
| ) | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment