1 | initial version |
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.