Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Problem with skip function before initializing all pages #196

Closed
YounisHamasur opened this issue Sep 3, 2023 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@YounisHamasur
Copy link

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();
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 YounisHamasur added the bug Something isn't working label Sep 3, 2023
@YounisHamasur YounisHamasur changed the title Bug: Problem with skip function before initializing all screens Bug: Problem with skip function before initializing all pages Sep 3, 2023
@mohsen0fc
Copy link

I also have this problem

@Pyozer
Copy link
Owner

Pyozer commented Mar 23, 2024

Fix in new version 3.1.13

@Pyozer Pyozer closed this as completed Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants