To include action icons to the AppBar when using the go_router in Flutter, you can use the AppBar's actions parameter. Here's an example code snippet:
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final router = GoRouter(
routes: [
GoRoute(
path: '/',
pageBuilder: (context, state) => MyHomePage(),
),
],
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerDelegate: router.delegate(),
routeInformationParser: router.routeInformationParser(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
actions: [
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () {},
),
],
),
body: Center(
child: Text('Hello, World!'),
),
);
}
}
In this example, we added two IconButton widgets to the actions parameter of the AppBar. The first IconButton uses the Icons.search icon and the second IconButton uses the Icons.more_vert icon. Both icons have an empty onPressed function for demonstration purposes.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-11 19:33:06 +0000
Seen: 13 times
Last updated: Jun 11 '23
How can zooming similar to desktop be achieved in HTML webview browser using Flutter?
In what way can the appleID signin be utilized in flutter?
How to maintain state across different pages using flutter?
How can I change a CameraImage Stream into bytes or a file in Flutter?
How can the current page context be obtained by a Flutter GetX controller?