home_stack.dart 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'package:app_flowy/startup/startup.dart';
  2. import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
  3. import 'package:flowy_log/flowy_log.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:time/time.dart';
  6. // [[diagram: HomeStack's widget structure]]
  7. //
  8. // ┌──────────────────┐ ┌───────────────┐
  9. // ┌──│BlankStackContext │──▶│BlankStackPage │
  10. // ┌──────────┐ ┌───────────────────┐ ┌─────────────────┐ │ └──────────────────┘ └───────────────┘
  11. // │HomeStack │─▶│ HomeStackManager │──▶│HomeStackContext │◀─┤
  12. // └──────────┘ └───────────────────┘ └─────────────────┘ │ ┌─────────────────┐ ┌────────────┐
  13. // └──│ DocStackContext │───▶│DocStackPage│
  14. // └─────────────────┘ └────────────┘
  15. //
  16. //
  17. class HomeStack extends StatelessWidget {
  18. static GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
  19. // final Size size;
  20. const HomeStack({Key? key}) : super(key: key);
  21. @override
  22. Widget build(BuildContext context) {
  23. Log.info('HomePage build');
  24. return Column(
  25. mainAxisAlignment: MainAxisAlignment.start,
  26. children: [
  27. getIt<HomeStackManager>().stackTopBar(),
  28. Expanded(
  29. child: Container(
  30. color: Colors.white,
  31. child: FocusTraversalGroup(
  32. child: getIt<HomeStackManager>().stackWidget(),
  33. ),
  34. ),
  35. ),
  36. ],
  37. );
  38. }
  39. }
  40. class FadingIndexedStack extends StatefulWidget {
  41. final int index;
  42. final List<Widget> children;
  43. final Duration duration;
  44. const FadingIndexedStack({
  45. Key? key,
  46. required this.index,
  47. required this.children,
  48. this.duration = const Duration(
  49. milliseconds: 250,
  50. ),
  51. }) : super(key: key);
  52. @override
  53. _FadingIndexedStackState createState() => _FadingIndexedStackState();
  54. }
  55. class _FadingIndexedStackState extends State<FadingIndexedStack> {
  56. double _targetOpacity = 1;
  57. @override
  58. void didUpdateWidget(FadingIndexedStack oldWidget) {
  59. if (oldWidget.index == widget.index) return;
  60. setState(() => _targetOpacity = 0);
  61. Future.delayed(1.milliseconds, () => setState(() => _targetOpacity = 1));
  62. super.didUpdateWidget(oldWidget);
  63. }
  64. @override
  65. Widget build(BuildContext context) {
  66. return TweenAnimationBuilder<double>(
  67. duration: _targetOpacity > 0 ? widget.duration : 0.milliseconds,
  68. tween: Tween(begin: 0, end: _targetOpacity),
  69. builder: (_, value, child) {
  70. return Opacity(opacity: value, child: child);
  71. },
  72. child: IndexedStack(index: widget.index, children: widget.children),
  73. );
  74. }
  75. }