Skip to content

Instantly share code, notes, and snippets.

@isaacadariku
Created December 22, 2022 23:12
Show Gist options
  • Save isaacadariku/ee2949fae8e8879b95356a04cfcf1adb to your computer and use it in GitHub Desktop.
Save isaacadariku/ee2949fae8e8879b95356a04cfcf1adb to your computer and use it in GitHub Desktop.
Accessibility Button Demo 

Accessibility Button Demo 

Created with <3 with dartpad.dev.

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const FontSizeChanger(),
);
}
}
class FontSizeChanger extends StatefulWidget {
const FontSizeChanger({super.key});
@override
State<FontSizeChanger> createState() => _FontSizeChangerState();
}
class _FontSizeChangerState extends State<FontSizeChanger> {
double _fontSize = 14.0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Accessibility Button Demo'),
),
body: Center(
child: Semantics(
label: 'Increase font size', // <-- Semantics label
child: Focus(
onFocusChange: (hasFocus) {
if (hasFocus) {
setState(() {
_fontSize += 2.0;
});
}
},
child: Text(
'Hello World',
style: TextStyle(fontSize: _fontSize),
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment