introduction_screen icon indicating copy to clipboard operation
introduction_screen copied to clipboard

Bug: Problem with skip function before initializing all pages

Open YounisHamasur opened this issue 2 years ago • 1 comments

I faced an issue when taping skip button and let the app navigate to another page it will throw an exception with the following details:

AssertionError ('package:flutter/src/widgets/page_view.dart': Failed assertion: line 170 pos 7: 'positions.isNotEmpty': PageController.page cannot be accessed before a PageView is built with it.)

this issue is reproduceable and I shared an example bellow, another point is when I click next and go through all pages then click done, the exception will not occur.

-first page example:

`import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:introduction_screen/introduction_screen.dart'; import 'package:testgetx/pagetwo.dart';

import 'controller.dart';

class PageOne extends StatelessWidget { PageOne({super.key}); final introKey = GlobalKey<IntroductionScreenState>(); void _onIntroEnd(context) { Navigator.of(context) .pushReplacement(MaterialPageRoute(builder: (context) => PageTwo())); }

@override Widget build(BuildContext context) { var bodyStyle = TextStyle(fontSize: 12); var pageDecoration = PageDecoration( titleTextStyle: TextStyle( fontSize: 14, fontWeight: FontWeight.w700, ), bodyTextStyle: bodyStyle, bodyPadding: EdgeInsets.all(0), pageColor: Colors.white, imagePadding: EdgeInsets.all(0), fullScreen: true, contentMargin: EdgeInsets.all(0));

return IntroductionScreen(
  key: introKey,
  globalBackgroundColor: Colors.white,
  allowImplicitScrolling: true,
  autoScrollDuration: 3000,
  infiniteAutoScroll: false,
  // globalHeader: Align(),
  // globalFooter: SizedBox(),
  pages: [
    introPageView("", pageDecoration, "title1", "body1", context),
    introPageView("", pageDecoration, "title2", "body2", context),
    introPageView("", pageDecoration, "title3", "body3", context)
  ],
  onDone: () => _onIntroEnd(context),
  onSkip: () =>
      _onIntroEnd(context), // You can override onSkip callback
  showSkipButton: true,
  skipOrBackFlex: 0,
  nextFlex: 0,
  showBackButton: false,
  //rtl: true, // Display as right-to-left
  back: const Icon(Icons.arrow_back),
  skip: Text("Skip".tr,
      style: TextStyle(
        fontWeight: FontWeight.w600,
        color: Colors.blueAccent,
      )),
  next: const Icon(Icons.arrow_forward, color: Colors.blueAccent),
  done: Text("Done".tr,
      style: TextStyle(
          fontWeight: FontWeight.w600,
          color: Colors.blueAccent,
          height: 1)),
  curve: Curves.fastLinearToSlowEaseIn,
  controlsMargin: const EdgeInsets.all(0),
  controlsPadding: EdgeInsets.all(0),
  dotsDecorator: const DotsDecorator(
    size: Size(10.0, 10.0),
    color: Colors.blueAccent,
    activeSize: Size(22.0, 10.0),
    activeColor: Colors.blueAccent,
    activeShape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(25.0)),
    ),
  ),
  dotsContainerDecorator: ShapeDecoration(
    color: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(8.0)),
    ),
  ),
);

}

PageViewModel introPageView( imageName, PageDecoration pageDecoration, title, body, context) { return PageViewModel( title: title, body: body, image: null, decoration: pageDecoration, ); }

Widget _buildImage(String assetName, context, [double width = 350]) { return Container( padding: EdgeInsets.only(bottom: 20, left: 0, right: 0, top: 0), child: Image.asset( 'assets/images/$assetName', //height: MediaQuery.of(context).size.height / 1.2, ), ); } } `

and this is just pagetwo

`import 'package:flutter/material.dart';

class PageTwo extends StatelessWidget { const PageTwo({super.key});

@override Widget build(BuildContext context) { return Container( color: Colors.white, child: Column( children: [ Center( child: Text("pagetwo"), ), ], )); } } `

YounisHamasur avatar Sep 03 '23 07:09 YounisHamasur

I also have this problem

mohsen0fc avatar Sep 10 '23 12:09 mohsen0fc

Fix in new version 3.1.13

Pyozer avatar Mar 23 '24 16:03 Pyozer