DolDurma
DolDurma

Reputation: 17289

flutter using pageview into appbar

in my application i want to show some container into AppBar like with PageView and i want to change index of the page view to show specific view, for example you suppose i have 4 Widget tree like with:

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' ), ),

i want to put them into PageView and putting thePageView into 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();
  }
}

for this implementation i get error:

════════ (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

Upvotes: 0

Views: 780

Answers (1)

Jim
Jim

Reputation: 7601

you need to put your pageview in a container and define width and height

Upvotes: 1

Related Questions