Last active
October 4, 2021 04:56
-
-
Save abhaysood/b14e9378c32ec9b1b24778479f3fe347 to your computer and use it in GitHub Desktop.
Trigger semantics action in widget tests (medium_blog)
This file contains 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
import 'package:flutter/material.dart'; | |
class MyApp extends StatelessWidget { | |
static const String label = "Hello World!"; | |
void _showSnackbar(BuildContext context, String message) { | |
ScaffoldMessenger.of(context).showSnackBar( | |
SnackBar( | |
content: Text(message), | |
duration: const Duration(milliseconds: 1500), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Semantics( | |
child: const Text(label), | |
onTap: () => _showSnackbar(context, "onTap"), | |
onDidGainAccessibilityFocus: () => | |
_showSnackbar(context, "onDidGainAccessibilityFocus"), | |
onDidLoseAccessibilityFocus: () => | |
_showSnackbar(context, "onDidLoseAccessibilityFocus"), | |
), | |
ElevatedButton( | |
child: const Text("button"), | |
onPressed: () {}, | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment