Sou novo no Flutter e usei dois ícones no topo, por isso meu título não fica centralizado. Também usei o widget central, mas também não funcionou.
Aqui está meu código do appbar:
appBar: AppBar(
automaticallyImplyLeading: false,
title: Stack(
children: [
Center(
child: Text(
_appBarTitle,
style: const TextStyle(color: Colors.white),
),
),
],
),
backgroundColor: AppColors.appbarColor,
scrolledUnderElevation: 0,
leading:const SizedBox(
width: 70,
),
actions: [
IconButton(
onPressed: () {
setState(() {
_isSearchVisible = !_isSearchVisible;
});
},
icon:const Icon(Icons.search, size: 30, color: Colors.white),
),
IconButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => const CartScreen()));
},
icon: const Icon(Icons.shopping_cart, size: 30, color: Colors.white),
),
],
),
Como você pode ver, isso não está perfeitamente centralizado.
Basta usar
centerTitle: true
no seuAppBar
.