barrier_free_navigation 1.0.2 copy "barrier_free_navigation: ^1.0.2" to clipboard
barrier_free_navigation: ^1.0.2 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 extends 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))),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
6
likes
0
points
361
downloads

Publisher

unverified uploader

Weekly Downloads

A highly customizable 3-tier Barrier-Free keyboard navigation package for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on barrier_free_navigation