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.

199 lines
8.0 KiB

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