Я новичок в флаттере, и у меня есть общий appBar, отделенный от main.dart, поэтому я могу использовать его на каждом экране. Вот файл dart с appBar.
import 'package:flutter/material.dart';
import 'package:voota/utils/Hex2Color.dart';
import 'package:intl/intl.dart';
class BaseAppBar extends StatelessWidget implements PreferredSizeWidget {
final Color bgColor = HexToColor('#508bbb');
final String title;
final AppBar appBar;
final List<Widget> widgets;
BaseAppBar({Key key, this.title, this.appBar, this.widgets})
: super(key: key);
@override
Widget build(BuildContext context) {
DateTime now = DateTime.now();
String formattedDate = DateFormat('MMMM d, y').format(now);
return AppBar(
title: RichText(
text: TextSpan(
text: 'VOOTA ' + title,
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
),
children: [
TextSpan(text: '\n'),
TextSpan(
text: formattedDate,
style: TextStyle(
fontSize: 10.0,
color: Colors.white,
),
),
]),
textAlign: TextAlign.center,
),
centerTitle: true,
backgroundColor: bgColor,
elevation: 0,
//actions: widgets,
);
}
@override
Size get preferredSize => new Size.fromHeight(appBar.preferredSize.height);
}
Я просто импортирую файл dart, в котором определен appBar, и поэтому на каждом экране у меня есть один и тот же appBar, например:
Widget build(BuildContext context) {
return Scaffold(
appBar: BaseAppBar(title: title, appBar: AppBar()),
....
Теперь мне нужна кнопка действия (раскрывающееся меню переполнения) на некоторых экранах. Но действия различаются от экрана к экрану. Как я могу это определить? На одном экране есть только обновление в меню выбора, а на другом экране есть обновление, выход из системы и параметры активации с разными маршрутами. А на панели инструментов вообще нет никаких действий ... Спасибо за любую помощь, совет или ссылку;)