Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rena2019/d50ab71b15e46d4ec46cdd068692f8e9 to your computer and use it in GitHub Desktop.

Select an option

Save rena2019/d50ab71b15e46d4ec46cdd068692f8e9 to your computer and use it in GitHub Desktop.
//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