mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

added functionality to onPressed method to communicate button press action to screen readers. Before: https://screencast.googleplex.com/cast/NjI2NzEyMzY3OTYyNTIxNnw1NjgyNGE3MC0wNQ After: https://screencast.googleplex.com/cast/NjUyODAxNzc0MzQ3ODc4NHwxNjBhZDZjNi1hOA fixes b/347102786
75 lines
1.9 KiB
Dart
75 lines
1.9 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'use_cases.dart';
|
|
|
|
class TextButtonUseCase extends UseCase {
|
|
|
|
@override
|
|
String get name => 'TextButton';
|
|
|
|
@override
|
|
String get route => '/text-button';
|
|
|
|
@override
|
|
Widget build(BuildContext context) => const MainWidget();
|
|
}
|
|
|
|
class MainWidget extends StatefulWidget {
|
|
const MainWidget({super.key});
|
|
|
|
@override
|
|
State<MainWidget> createState() => MainWidgetState();
|
|
}
|
|
|
|
class MainWidgetState extends State<MainWidget> {
|
|
int _count = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
title: const Text('TextButton'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
MergeSemantics(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
const Text('This is a TextButton:'),
|
|
TextButton(
|
|
onPressed: () {
|
|
setState(() { _count++; });
|
|
},
|
|
child: const Text('Action'),
|
|
),
|
|
Text('Clicked $_count time(s).'),
|
|
],
|
|
),
|
|
),
|
|
const MergeSemantics(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text('This is a disabled TextButton:'),
|
|
TextButton(
|
|
onPressed: null,
|
|
child: Text('Action Disabled'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|