Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. Widget buildPageViewTest(TickerProvider tickerProvider) {
  2. var colors = [
  3. [Colors.blue[800], Colors.orange],
  4. [Colors.green[800], Colors.red]
  5. ];
  6. const int CYCLES = 20;
  7. int numPages = 2;
  8. Random rnd = Random();
  9. Stream<int> stream = Stream.periodic(Duration(seconds: 3))
  10. .map((_) => numPages += 1 + rnd.nextInt(2))
  11. .take(CYCLES);
  12.  
  13. AnimationController animation = AnimationController(
  14. vsync: tickerProvider,
  15. duration: Duration(seconds: 3 * CYCLES),
  16. upperBound: CYCLES.toDouble(),
  17. );
  18. animation.forward();
  19.  
  20. return Column(
  21. children: <Widget>[
  22. RotationTransition(
  23. turns: animation,
  24. child: Icon(
  25. Icons.refresh,
  26. size: 100.0,
  27. ),
  28. ),
  29. StreamBuilder(
  30. stream: stream,
  31. initialData: 1,
  32. builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
  33. int itemCount = snapshot.data;
  34. print("StreamBuilder itemCount: $itemCount");
  35. return Expanded(
  36. child: PageView.builder(
  37. itemCount: itemCount,
  38. itemBuilder: (ctx, idx) {
  39. return AnimatedSwitcher(
  40. duration: Duration(milliseconds: 500),
  41. child: Text(
  42. idx == itemCount - 1
  43. ? "last page"
  44. : "page\n${idx + 1} of $itemCount",
  45. key: ValueKey<String>("$idx:$itemCount"),
  46. textAlign: TextAlign.center,
  47. style: TextStyle(
  48. color: colors[itemCount % 2][idx % 2],
  49. fontSize: 80.0,
  50. fontWeight: FontWeight.bold,
  51. ),
  52. ),
  53. );
  54. },
  55. ),
  56. );
  57. },
  58. ),
  59. ],
  60. );
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement