example_actions_widget.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. typedef ExampleActionsBuilder = Widget Function(
  4. BuildContext context, bool isLayoutHorizontal);
  5. class ExampleActionsWidget extends StatelessWidget {
  6. const ExampleActionsWidget({
  7. Key? key,
  8. required this.displayContentBuilder,
  9. this.actionsBuilder,
  10. }) : super(key: key);
  11. final ExampleActionsBuilder displayContentBuilder;
  12. final ExampleActionsBuilder? actionsBuilder;
  13. @override
  14. Widget build(BuildContext context) {
  15. final mediaData = MediaQuery.of(context);
  16. final bool isLayoutHorizontal = mediaData.size.aspectRatio >= 1.5 ||
  17. (kIsWeb ||
  18. !(defaultTargetPlatform == TargetPlatform.android ||
  19. defaultTargetPlatform == TargetPlatform.iOS));
  20. if (actionsBuilder == null) {
  21. return displayContentBuilder(context, isLayoutHorizontal);
  22. }
  23. const actionsTitle = Text(
  24. 'Actions',
  25. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24),
  26. );
  27. if (isLayoutHorizontal) {
  28. return Row(
  29. mainAxisAlignment: MainAxisAlignment.start,
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. mainAxisSize: MainAxisSize.max,
  32. children: [
  33. Expanded(
  34. flex: 1,
  35. child: SingleChildScrollView(
  36. child: Container(
  37. padding: const EdgeInsets.fromLTRB(16, 24, 16, 24),
  38. child: Column(
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. mainAxisAlignment: MainAxisAlignment.start,
  41. mainAxisSize: MainAxisSize.max,
  42. children: [
  43. actionsTitle,
  44. actionsBuilder!(context, isLayoutHorizontal),
  45. ],
  46. ),
  47. ),
  48. ),
  49. ),
  50. Container(
  51. color: Colors.grey.shade100,
  52. width: 20,
  53. ),
  54. Expanded(
  55. flex: 2,
  56. child: displayContentBuilder(context, isLayoutHorizontal),
  57. ),
  58. ],
  59. );
  60. }
  61. return Stack(
  62. children: [
  63. SizedBox.expand(
  64. child: Container(
  65. padding: const EdgeInsets.only(bottom: 150),
  66. child: displayContentBuilder(context, isLayoutHorizontal),
  67. ),
  68. ),
  69. DraggableScrollableSheet(
  70. initialChildSize: 0.25,
  71. snap: true,
  72. maxChildSize: 0.7,
  73. builder: (BuildContext context, ScrollController scrollController) {
  74. return Container(
  75. decoration: const BoxDecoration(
  76. color: Color.fromARGB(255, 253, 253, 253),
  77. borderRadius: BorderRadius.only(
  78. topLeft: Radius.circular(24.0),
  79. topRight: Radius.circular(24.0),
  80. ),
  81. boxShadow: [
  82. BoxShadow(
  83. blurRadius: 20.0,
  84. color: Colors.grey,
  85. ),
  86. ]),
  87. padding: const EdgeInsets.fromLTRB(16, 24, 16, 0),
  88. child: SingleChildScrollView(
  89. controller: scrollController,
  90. child: Column(
  91. crossAxisAlignment: CrossAxisAlignment.start,
  92. mainAxisAlignment: MainAxisAlignment.start,
  93. mainAxisSize: MainAxisSize.max,
  94. children: [
  95. actionsTitle,
  96. actionsBuilder!(context, isLayoutHorizontal),
  97. ],
  98. ),
  99. ),
  100. );
  101. },
  102. )
  103. ],
  104. );
  105. }
  106. }