I’m using appbar and I’ve added an Icon button in the leading.
by making the app RTL this button stays on the left and won’t come right.
because app is multi language and should support RTL. all the parts works but the appbar doesn’t.
// AppBar
appBar: AppBar(
// automaticallyImplyLeading: false,
elevation: 0.5,
centerTitle: true,
title: ValueListenableBuilder(
valueListenable: globals.selectedBarIndex,
builder: (context, value, Widget? child) {
return Text(globals.navBarItems[globals.selectedBarIndex.value].text);
},
),
leading: IconButton(
onPressed: _handleMenuButtonPressed,
icon: ValueListenableBuilder<AdvancedDrawerValue>(
valueListenable: widget.advancedDrawerController,
builder: (_, value, __) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: Icon(
value.visible ? Icons.clear : Icons.menu,
key: ValueKey<bool>(value.visible),
),
);
},
),
),
),
2
Answers
To properly support RTL (Right-to-Left) in your app’s AppBar and handle the positioning of the leading IconButton based on the text direction, you can use the Directionality widget. Here’s an example of how you can modify your AppBar code.Please check this this below code
You must use the Directionality widget.
To use Directionality in the AppBar, see the following code: