в моем приложении я хочу показать некоторый контейнер в AppBar
, как с PageView
, и я хочу изменить индекс представления страницы, чтобы показать конкретное представление c, например, вы предполагаете, что у меня есть дерево 4 Widget
как с:
Container( width: double.infinity, child: const Text( 'Appbar 1' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 2' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 3' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 4' ), ),
я хочу поместить их в PageView
и положить PageView
в Appbar
class AppToolbar extends State<ApplicationToolbar> {
PageController _appBarPageController;
@override
void initState() {
super.initState();
_appBarPageController = PageController(initialPage: 0, keepPage: true);
}
@override
Widget build(BuildContext context) {
return AppBar(
automaticallyImplyLeading: false,
elevation: 8.0,
titleSpacing: 0.0,
title: PageView(
controller: _appBarPageController,
scrollDirection: Axis.vertical,
children: <Widget>[
Container( width: double.infinity, child: const Text( 'Appbar 1' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 2' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 3' ), ),
Container( width: double.infinity, child: const Text( 'Appbar 4' ), ),
],
)
);
}
@override
void dispose() {
super.dispose();
_appBarPageController.dispose();
}
}
для этой реализации я получаю ошибку:
════════ (16) Exception caught by rendering library ═══════
RenderBox was not laid out: RenderRepaintBoundary#3a85a relayoutBoundary=up14 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1694 pos 12: 'hasSize'
The relevant error-causing widget was:
AppBar file:///C:/Users/mahdi/AndroidStudioProjects/xxx/lib/ui_helper/widgets/application_toolbar.dart:36:12