BlockSemantics Widget
Project Preview
- Interested in seeing the live demo? Click here to explore.
- Want to view the source code? Visit the project on GitHub.
Code Snippet
import 'package:flutter/material.dart';
class BlockSemanticsWidget extends StatelessWidget {
const BlockSemanticsWidget({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
showSemanticsDebugger: true, // Set as true
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isShow = false;
@override
Widget build(BuildContext context) {
return SizedBox(
width: double.infinity,
child: SizedBox(
width: 500,
height: double.infinity,
child: Column(
children: [
OutlinedButton(
onPressed: () => setState(() {
isShow = true;
}),
child: const Text(
'Click',
),
),
if (isShow)
BlockSemantics(
blocking: isShow,
child: Card(
color: Colors.orangeAccent,
child: SizedBox(
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('This is a card'),
TextButton(
onPressed: () => setState(
() {
isShow = false;
},
),
child: const Text('Close'),
)
],
),
),
),
)
],
),
),
);
}
}