Skip to content

Commit 830b4b7

Browse files
committed
feat(accessibility): Add progressSemantic for customizable progress indicator semantics
This commit introduces a new optional parameter `progressSemantic` to the `IntroductionScreen` widget. This parameter allows developers to provide a custom semantic label for the progress indicator (dots or custom progress). If `progressSemantic` is provided, it will be used to generate the semantic label. Otherwise, a default label "Page {currentPage} of {totalPages}" will be used. This change enhances accessibility by allowing developers to provide more contextually relevant information to users relying on screen readers.
1 parent f878eba commit 830b4b7

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

lib/src/introduction_screen.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ library introduction_screen;
22

33
import 'dart:async';
44
import 'dart:math';
5-
6-
import 'package:flutter/material.dart';
5+
import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';
76

87
import 'package:collection/collection.dart';
98
import 'package:dots_indicator/dots_indicator.dart';
9+
import 'package:flutter/material.dart';
1010
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
1111

1212
import '/src/helper.dart';
@@ -199,6 +199,9 @@ class IntroductionScreen extends StatefulWidget {
199199
/// Back button semantic label
200200
final String? backSemantic;
201201

202+
/// Progress indicator semantic label
203+
final String Function(int, int)? progressSemantic;
204+
202205
/// Enable or disable content resizing for bottom inset (e.g. keyboard)
203206
///
204207
/// @Default `true`
@@ -324,6 +327,7 @@ class IntroductionScreen extends StatefulWidget {
324327
this.nextSemantic,
325328
this.doneSemantic,
326329
this.backSemantic,
330+
this.progressSemantic,
327331
this.resizeToAvoidBottomInset = true,
328332
this.controlsPosition = const Position(left: 0, right: 0, bottom: 0),
329333
this.controlsMargin = EdgeInsets.zero,
@@ -680,8 +684,12 @@ class IntroductionScreenState extends State<IntroductionScreen> {
680684
child: widget.isProgress
681685
? widget.customProgress ??
682686
Semantics(
683-
label:
684-
"Page ${getCurrentPage() + 1} of ${getPagesLength()}",
687+
label: widget.progressSemantic != null
688+
? widget.progressSemantic!(
689+
getCurrentPage() + 1,
690+
getPagesLength())
691+
.call()
692+
: "Page ${getCurrentPage() + 1} of ${getPagesLength()}",
685693
excludeSemantics: true,
686694
child: DotsIndicator(
687695
reversed: widget.rtl,

0 commit comments

Comments
 (0)