barrier_free_navigation 1.0.0
barrier_free_navigation: ^1.0.0 copied to clipboard
A highly customizable 3-tier Barrier-Free keyboard navigation package for Flutter.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:barrier_free_navigation/barrier_free_navigation.dart';
void main() {
runApp(const MyApp());
}
class MyTTSDelegate implements BarrierFreeDelegate {
@override
bool get isBarrierFreeModeEnabled => true;
@override
bool get isVoiceGuideEnabled => true;
@override
void speak(String text, {bool isFilter = true}) {
// Print instead of actual TTS for the sake of simple example
debugPrint('๐ฃ๏ธ [TTS SPEAK]: $text');
}
@override
void playClickSound() {
debugPrint('๐ [CLICK SOUND]');
}
@override
void onVolumeUp() => debugPrint('Volume Up');
@override
void onVolumeDown() => debugPrint('Volume Down');
@override
void onCustomKey1() => debugPrint('Custom Key 1');
@override
void onCustomKey2() => debugPrint('Custom Key 2');
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
BarrierFreeManager.instance.initialize(
delegate: MyTTSDelegate(),
config: BFKeyboardConfig(
groupUpKey: PhysicalKeyboardKey.arrowUp,
groupDownKey: PhysicalKeyboardKey.arrowDown,
itemPreviousKey: PhysicalKeyboardKey.arrowLeft,
itemNextKey: PhysicalKeyboardKey.arrowRight,
volumeUpKey: PhysicalKeyboardKey.pageUp,
volumeDownKey: PhysicalKeyboardKey.pageDown,
customKey1: PhysicalKeyboardKey.f1,
customKey2: PhysicalKeyboardKey.f2,
enterKey: PhysicalKeyboardKey.enter,
),
);
WidgetsBinding.instance.addPostFrameCallback((_) {
BarrierFreeManager.instance
.speak("๋ฐฐ๋ฆฌ์ด ํ๋ฆฌ ๋ฐ๋ชจ ํ๋ฉด์
๋๋ค. ๊ทธ๋ฃน๊ฐ ์ด๋์ ์ํ ๋ฐฉํฅํค๋ฅผ, ์์ดํ
๊ฐ ์ด๋์ ์ข์ฐ ๋ฐฉํฅํค๋ฅผ ์ฌ์ฉํ์ธ์.");
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const BarrierFreeExampleScreen(),
);
}
}
class BarrierFreeExampleScreen extends StatefulWidget {
const BarrierFreeExampleScreen({super.key});
@override
State<BarrierFreeExampleScreen> createState() =>
_BarrierFreeExampleScreenState();
}
class _BarrierFreeExampleScreenState extends State<BarrierFreeExampleScreen> {
final FocusNode _topRowFocus = FocusNode();
final FocusNode _middleFocus = FocusNode();
@override
void dispose() {
_topRowFocus.dispose();
_middleFocus.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BFFocusCoordinator(
routeName: '/example',
focusGroups: [
FocusGroupConfig(focusNode: _topRowFocus, isSingleChild: false),
FocusGroupConfig(focusNode: _middleFocus, isSingleChild: true),
],
child: Scaffold(
appBar: AppBar(
title: const Text('Barrier-Free Example'),
),
body: Column(
children: [
const SizedBox(height: 50),
// Group 1: A row of buttons (isSingleChild: false)
BFAreaFocusGroup(
focusNode: _topRowFocus,
ttsMsg: '์๋จ ๋ฒํผ ๊ทธ๋ฃน์
๋๋ค.',
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
BFFocusItem(
ttsMsg: '์ฒซ ๋ฒ์งธ ๋ฒํผ',
onTap: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('๋ฒํผ 1 ๋๋ฆผ')),
),
child: Container(
padding: const EdgeInsets.all(20),
color: Colors.blue.withAlpha(128), // withOpacity(0.5)
child: const Text('๋ฒํผ 1'),
),
),
BFFocusItem(
ttsMsg: '๋ ๋ฒ์งธ ๋ฒํผ',
onTap: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('๋ฒํผ 2 ๋๋ฆผ')),
),
child: Container(
padding: const EdgeInsets.all(20),
color: Colors.green.withAlpha(128), // withOpacity(0.5)
child: const Text('๋ฒํผ 2'),
),
),
],
),
),
const SizedBox(height: 50),
// Group 2: A single large target (isSingleChild: true)
BFAreaFocusGroup(
focusNode: _middleFocus,
ttsMsg: '',
child: BFFocusItem(
ttsMsg: 'ํ๋จ ํ์ธ ๋ฒํผ์
๋๋ค.',
onTap: () => ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('ํ์ธ ์๋ฃ')),
),
child: Container(
width: 300,
padding: const EdgeInsets.all(40),
color: Colors.redAccent.withAlpha(128), // withOpacity(0.5)
child: const Center(
child: Text('ํ์ธ', style: TextStyle(fontSize: 24))),
),
),
),
],
),
),
);
}
}