You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
7.8 KiB

2 years ago
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:my_flutter_puzzle/providers.dart';
  4. import 'package:palette_generator/palette_generator.dart';
  5. class ImageViewer extends ConsumerWidget {
  6. const ImageViewer({
  7. required this.puzzleSize,
  8. required this.previousImage,
  9. required this.previousPalette,
  10. required this.imageSize,
  11. Key? key,
  12. }) : super(key: key);
  13. final int puzzleSize;
  14. final Image? previousImage;
  15. final PaletteGenerator? previousPalette;
  16. final double imageSize;
  17. @override
  18. Widget build(BuildContext context, WidgetRef ref) {
  19. return Consumer(
  20. builder: (context, ref, child) {
  21. final state = ref.watch(imageSplitterNotifierProvider);
  22. return state.maybeWhen(
  23. () => const SizedBox(),
  24. complete: (image, images, palette) => Padding(
  25. padding: const EdgeInsets.only(right: 0.0),
  26. child: Column(
  27. mainAxisSize: MainAxisSize.min,
  28. children: [
  29. Container(
  30. decoration: BoxDecoration(
  31. borderRadius: BorderRadius.circular(20),
  32. // border: Border.all(color: Colors.white, width: 3),
  33. ),
  34. child: ClipRRect(
  35. borderRadius: BorderRadius.circular(20),
  36. child: Image(
  37. image: image.image,
  38. height: imageSize,
  39. width: imageSize,
  40. ),
  41. ),
  42. ),
  43. Padding(
  44. padding: const EdgeInsets.only(top: 8.0),
  45. child: SizedBox(
  46. width: imageSize,
  47. child: Padding(
  48. padding: const EdgeInsets.symmetric(
  49. vertical: 4,
  50. horizontal: 16,
  51. ),
  52. child: Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  54. children: [
  55. Container(
  56. width: imageSize / 5,
  57. height: imageSize / 5,
  58. decoration: BoxDecoration(
  59. color: palette.colors.elementAt(0),
  60. shape: BoxShape.circle,
  61. border: Border.all(
  62. color: Colors.white60,
  63. width: 3,
  64. ),
  65. ),
  66. ),
  67. Container(
  68. width: imageSize / 5,
  69. height: imageSize / 5,
  70. decoration: BoxDecoration(
  71. color: palette.colors.elementAt(1),
  72. shape: BoxShape.circle,
  73. border: Border.all(
  74. color: Colors.white60,
  75. width: 3,
  76. ),
  77. ),
  78. ),
  79. Container(
  80. width: imageSize / 5,
  81. height: imageSize / 5,
  82. decoration: BoxDecoration(
  83. color: palette.colors.elementAt(2),
  84. shape: BoxShape.circle,
  85. border: Border.all(
  86. color: Colors.white60,
  87. width: 3,
  88. ),
  89. ),
  90. ),
  91. ],
  92. ),
  93. ),
  94. ),
  95. ),
  96. const SizedBox(height: 16),
  97. // PickImageButton(
  98. // text: 'Pick Image',
  99. // onTap: () => ref
  100. // .read(imageSplitterNotifierProvider.notifier)
  101. // .generateImages(
  102. // picker: imagePicker,
  103. // puzzleSize: puzzleSize,
  104. // ),
  105. // ),
  106. ],
  107. ),
  108. ),
  109. orElse: () => previousImage != null
  110. ? Padding(
  111. padding: const EdgeInsets.only(right: 0.0),
  112. child: Column(
  113. mainAxisSize: MainAxisSize.min,
  114. children: [
  115. Container(
  116. decoration: BoxDecoration(
  117. borderRadius: BorderRadius.circular(20),
  118. // border: Border.all(color: Colors.white, width: 3),
  119. ),
  120. child: ClipRRect(
  121. borderRadius: BorderRadius.circular(20),
  122. child: Image(
  123. image: previousImage!.image,
  124. height: imageSize,
  125. width: imageSize,
  126. ),
  127. ),
  128. ),
  129. Padding(
  130. padding: const EdgeInsets.only(top: 8.0),
  131. child: SizedBox(
  132. width: imageSize,
  133. child: Padding(
  134. padding: const EdgeInsets.symmetric(
  135. vertical: 4,
  136. horizontal: 16,
  137. ),
  138. child: Row(
  139. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  140. children: [
  141. Container(
  142. width: imageSize / 5,
  143. height: imageSize / 5,
  144. decoration: BoxDecoration(
  145. color: previousPalette!.colors.elementAt(0),
  146. shape: BoxShape.circle,
  147. border: Border.all(
  148. color: Colors.white60,
  149. width: 3,
  150. ),
  151. ),
  152. ),
  153. Container(
  154. width: imageSize / 5,
  155. height: imageSize / 5,
  156. decoration: BoxDecoration(
  157. color: previousPalette!.colors.elementAt(1),
  158. shape: BoxShape.circle,
  159. border: Border.all(
  160. color: Colors.white60,
  161. width: 3,
  162. ),
  163. ),
  164. ),
  165. Container(
  166. width: imageSize / 5,
  167. height: imageSize / 5,
  168. decoration: BoxDecoration(
  169. color: previousPalette!.colors.elementAt(2),
  170. shape: BoxShape.circle,
  171. border: Border.all(
  172. color: Colors.white60,
  173. width: 3,
  174. ),
  175. ),
  176. ),
  177. ],
  178. ),
  179. ),
  180. ),
  181. ),
  182. const SizedBox(height: 16),
  183. ],
  184. ),
  185. )
  186. : const SizedBox(),
  187. );
  188. },
  189. );
  190. }
  191. }