Closes https://github.com/flutter/flutter/issues/92040
- Adds `expanded` semantics flag support to Android
- Adds `onExpand` and `onCollapse` semantics actions
- Updates `robolectric` library
- Adds java and dart tests
#### Why were `onExpand` and `onCollapse` actions added?
It turned out that TalkBack doesn't announce the `expanded` state if
`expand/collapse` action is not set for the accessibility node.
#### Why was the `robolectric` library updated?
The `expanded` state support in Android was introduced in API 36. The
`roboelectric: 4.14.1` doesn't support API 36. To run tests for a newly
added functionality `roboelectric` library was updated to `4.16`, which
supports the latest Android version
(https://github.com/robolectric/robolectric/releases/tag/robolectric-4.16).
In case you think it would be better to update the `roboelectric` in a
separate PR, please let me know.
<br/>
<details>
<summary>Example Source Code</summary>
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
final _controller = ExpansibleController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 24,
children: [
Text('Expansible Example'),
ListenableBuilder(
listenable: _controller,
builder: (context, child) {
return Semantics(
expanded: _controller.isExpanded,
onExpand: () {
print(' \n onExpand \n ');
_controller.expand();
},
onCollapse: () {
print(' \n onCollapse \n ');
_controller.collapse();
},
child: child,
);
},
child: Expansible(
headerBuilder: (context, _) => ListTile(
tileColor: Colors.blue.shade100,
leading: Text(
'Expansible',
style: TextStyle(fontSize: 20),
),
trailing: Icon(
_controller.isExpanded
? Icons.arrow_upward
: Icons.arrow_downward,
semanticLabel: _controller.isExpanded
? 'Arrow Up icon'
: 'Arrow Down icon',
),
),
bodyBuilder: (context, _) {
return Container(
color: Colors.blue,
height: 200,
width: 200,
);
},
controller: _controller,
),
),
],
),
),
);
}
}
```
</details>
https://github.com/user-attachments/assets/256c4182-a1e3-44fc-b028-5e6c9ec05ad7
## Pre-launch Checklist
- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [X] All existing and new tests are passing.
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
---------
Co-authored-by: ash2moon <muhatashim@google.com>