details_placeholder_page.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. // TODO(yijing): delete this after implementing the real screen inside bottom navigation bar.
  4. /// For demonstration purposes
  5. class DetailsPlaceholderScreen extends StatefulWidget {
  6. /// Constructs a [DetailsScreen].
  7. const DetailsPlaceholderScreen({
  8. required this.label,
  9. this.param,
  10. this.extra,
  11. this.withScaffold = true,
  12. super.key,
  13. });
  14. /// The label to display in the center of the screen.
  15. final String label;
  16. /// Optional param
  17. final String? param;
  18. /// Optional extra object
  19. final Object? extra;
  20. /// Wrap in scaffold
  21. final bool withScaffold;
  22. @override
  23. State<StatefulWidget> createState() => DetailsPlaceholderScreenState();
  24. }
  25. /// The state for DetailsScreen
  26. class DetailsPlaceholderScreenState extends State<DetailsPlaceholderScreen> {
  27. int _counter = 0;
  28. @override
  29. Widget build(BuildContext context) {
  30. if (widget.withScaffold) {
  31. return Scaffold(
  32. appBar: AppBar(
  33. title: Text('Details Screen - ${widget.label}'),
  34. ),
  35. body: _build(context),
  36. );
  37. } else {
  38. return Container(
  39. color: Theme.of(context).scaffoldBackgroundColor,
  40. child: _build(context),
  41. );
  42. }
  43. }
  44. Widget _build(BuildContext context) {
  45. return Center(
  46. child: Column(
  47. mainAxisSize: MainAxisSize.min,
  48. children: <Widget>[
  49. Text(
  50. 'Details for ${widget.label} - Counter: $_counter',
  51. style: Theme.of(context).textTheme.titleLarge,
  52. ),
  53. const Padding(padding: EdgeInsets.all(4)),
  54. TextButton(
  55. onPressed: () {
  56. setState(() {
  57. _counter++;
  58. });
  59. },
  60. child: const Text('Increment counter'),
  61. ),
  62. const Padding(padding: EdgeInsets.all(8)),
  63. if (widget.param != null)
  64. Text(
  65. 'Parameter: ${widget.param!}',
  66. style: Theme.of(context).textTheme.titleMedium,
  67. ),
  68. const Padding(padding: EdgeInsets.all(8)),
  69. if (widget.extra != null)
  70. Text(
  71. 'Extra: ${widget.extra!}',
  72. style: Theme.of(context).textTheme.titleMedium,
  73. ),
  74. if (!widget.withScaffold) ...<Widget>[
  75. const Padding(padding: EdgeInsets.all(16)),
  76. TextButton(
  77. onPressed: () {
  78. GoRouter.of(context).pop();
  79. },
  80. child: const Text(
  81. '< Back',
  82. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  83. ),
  84. ),
  85. ]
  86. ],
  87. ),
  88. );
  89. }
  90. }