Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Widget buildPageViewTest(TickerProvider tickerProvider) {
- var colors = [
- [Colors.blue[800], Colors.orange],
- [Colors.green[800], Colors.red]
- ];
- const int CYCLES = 20;
- int numPages = 2;
- Random rnd = Random();
- Stream<int> stream = Stream.periodic(Duration(seconds: 3))
- .map((_) => numPages += 1 + rnd.nextInt(2))
- .take(CYCLES);
- AnimationController animation = AnimationController(
- vsync: tickerProvider,
- duration: Duration(seconds: 3 * CYCLES),
- upperBound: CYCLES.toDouble(),
- );
- animation.forward();
- return Column(
- children: <Widget>[
- RotationTransition(
- turns: animation,
- child: Icon(
- Icons.refresh,
- size: 100.0,
- ),
- ),
- StreamBuilder(
- stream: stream,
- initialData: 1,
- builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
- int itemCount = snapshot.data;
- print("StreamBuilder itemCount: $itemCount");
- return Expanded(
- child: PageView.builder(
- itemCount: itemCount,
- itemBuilder: (ctx, idx) {
- return AnimatedSwitcher(
- duration: Duration(milliseconds: 500),
- child: Text(
- idx == itemCount - 1
- ? "last page"
- : "page\n${idx + 1} of $itemCount",
- key: ValueKey<String>("$idx:$itemCount"),
- textAlign: TextAlign.center,
- style: TextStyle(
- color: colors[itemCount % 2][idx % 2],
- fontSize: 80.0,
- fontWeight: FontWeight.bold,
- ),
- ),
- );
- },
- ),
- );
- },
- ),
- ],
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement