I am trying to implement a custom app bar for child pages of my main page. However, whenever I go to the child page the button on the custom app bar does not work. The app bar is called within a Scaffold on each child page page.
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:../resources/constants.dart';
import 'package:../resources/text_styles.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
CustomAppBar(this.title);
final String title;
@override
Size get preferredSize => Size.fromHeight(40.0);
@override
Widget build(BuildContext context) {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: getAppBarWidgets(context),
),
);
}
List<Widget> getAppBarWidgets(BuildContext context) {
List<Widget> _appBarWidgets = [];
_appBarWidgets.add(
IconButton(
icon: Icon(
Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
size: 20.0,
),
onPressed: () {
Navigator.pop(context);
},
),
);
_appBarWidgets.add(
Text(
title,
textAlign: TextAlign.center,
style:
kHeadlineBase.copyWith(fontWeight: FontWeight.bold, fontSize: 12.0),
),
);
_appBarWidgets.add(SizedBox(
width: kAppBarMargin,
));
return _appBarWidgets;
}
}