Skip to content

Instantly share code, notes, and snippets.

@hectorAguero
Last active November 25, 2025 18:35
Show Gist options
  • Select an option

  • Save hectorAguero/c326400382414f80211c2e248e702ef6 to your computer and use it in GitHub Desktop.

Select an option

Save hectorAguero/c326400382414f80211c2e248e702ef6 to your computer and use it in GitHub Desktop.
Allow bool expanded
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final notifier = ValueNotifier<bool>(true);
var value = true;
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Column(
mainAxisSize: .min,
spacing: 16,
children: [MyWidget(expanded: notifier)],
),
),
floatingActionButton: FloatingActionButton.extended(
label: Text('Expand'),
onPressed: () {
notifier.value = true;
value = true;
},
),
),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key, required this.expanded});
final ValueNotifier<bool> expanded;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
expanded.value = !expanded.value;
},
child: ValueListenableBuilder(
valueListenable: expanded,
builder: (context, value, child) {
return AnimatedContainer(
duration: Durations.short1,
height: expanded.value ? 100 : 10,
width: 100,
color: Colors.red,
);
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment