animated theme switcher + page view = no scroll
Hello ! First of all, great widget. I'm using it all the time, love the little trick of taking the screenshot and removing it with an animation. It's simple and elegant.
With that said, I am using a PageView widget within the ThemeSwitchArea like this:
class _MyHomePageState extends State<MyHomePage> {
PageController pc = PageController();
@override
Widget build(BuildContext context) {
return ThemeSwitchingArea(
child: PageView(
controller: pc,
onPageChanged: (page) {
setState(() {
print("PAGE CHANGED TO ->${page}");
});
},
children: [
Container(
color: Colors.red,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.green,
)
],
),
);
}
}
This is what I replace the Widget Build function with, in a default flutter create project
When doing that, I can't swipe between the 3 pages anymore. The swiping animation starts on page 1 and rolls back to page 1 instead of displaying the page 2.
It's due to the setState call in the onPageChanged.
I didn't add my entire widget which has a FutureBuilder, AnimatedContainers, AnimatedPositionned plus a series of changes which require a call to SetState between every page.
Again, great widget, neat trick !
My Flutter doctor looks like this:
❯ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.0, on macOS 12.0.1 21A559 darwin-x64, locale en-BE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2021.2.3)
[✓] VS Code (version 1.63.1)
[✓] Connected device (2 available)
thanks for reporting this I'll take a look on the weekend
@kherel any updates?
What is happening when you separate page view widget?
@cekrozl1
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ThemeSwitchingArea(
child: const _PageView(),
);
}
}
class _PageView extends StatefulWidget {
const _PageView({Key? key}) : super(key: key);
@override
__PageViewState createState() => __PageViewState();
}
class __PageViewState extends State<_PageView> {
PageController pc = PageController();
@override
Widget build(BuildContext context) {
return PageView(
controller: pc,
onPageChanged: (page) {
setState(() {
print("PAGE CHANGED TO ->${page}");
});
},
children: [
Container(
color: Colors.red,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.green,
)
],
);
}
}
Hi @kherel !
Happy new year ! The solution above works fine. Thanks !
Is it okay if I keep the ticket open until I can implement the fix in the main project (not the test one)?