Flutter 在appbar中使用pageview进行颤振
在我的应用程序中,我想在AppBar中显示一些容器,如PageView,我想更改页面视图的索引以显示特定视图,例如,假设我有4个小部件树,如:Flutter 在appbar中使用pageview进行颤振,flutter,flutter-layout,Flutter,Flutter Layout,在我的应用程序中,我想在AppBar中显示一些容器,如PageView,我想更改页面视图的索引以显示特定视图,例如,假设我有4个小部件树,如: Container( width: double.infinity, child: const Text( 'Appbar 1' ), ), Container( width: double.infinity, child: const Text( 'Appbar 2' ), ), Container( width: double.infinity, c
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' ), ),
我想把它们放到页面视图中,然后把页面视图放到应用程序栏中
您需要将页面视图放在一个容器中,并定义宽度和高度
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