Skip to content

Commit e5bcf85

Browse files
Merge pull request #104 from SouksavathPMS/kyeDev
feat: #103 Add onTap call back on default preview item
2 parents 61b5cfd + b71957d commit e5bcf85

File tree

6 files changed

+125
-34
lines changed

6 files changed

+125
-34
lines changed

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
platform :ios, '11.0'
2+
platform :ios, '12.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ EXTERNAL SOURCES:
5959
SPEC CHECKSUMS:
6060
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
6161
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
62-
file_picker: ce3938a0df3cc1ef404671531facef740d03f920
63-
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
62+
file_picker: a0560bc09d61de87f12d246fc47d2119e6ef37be
63+
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
6464
SDWebImage: 1c39de67663e5eebb2f41324d5d580eeea12dd4c
6565
SwiftyGif: 93a1cc87bf3a51916001cf8f3d63835fb64c819f
6666

67-
PODFILE CHECKSUM: 241ff90fd4cafe2ad317569236de3a478bea1b03
67+
PODFILE CHECKSUM: c72a7f1dd1e058573ba6fd9cf4f251b60434bc5b
6868

69-
COCOAPODS: 1.11.3
69+
COCOAPODS: 1.16.2

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1515
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
1616
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
17+
DBD69ACC5CC460CA051D29E5 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C00575E57111313065C9F9B /* Pods_Runner.framework */; };
1718
/* End PBXBuildFile section */
1819

1920
/* Begin PBXContainerItemProxy section */
@@ -45,29 +46,45 @@
4546
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
4647
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4748
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
49+
4E85868E43666D91678AA906 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
4850
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
4951
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5052
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
53+
8C00575E57111313065C9F9B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5154
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
5255
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
5356
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
5457
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5558
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5659
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5760
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
61+
C77E02D8A7E5743EE4395169 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
62+
DB04B01663E9E9EC2B4EF6FF /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
5863
/* End PBXFileReference section */
5964

6065
/* Begin PBXFrameworksBuildPhase section */
6166
97C146EB1CF9000F007C117D /* Frameworks */ = {
6267
isa = PBXFrameworksBuildPhase;
6368
buildActionMask = 2147483647;
6469
files = (
70+
DBD69ACC5CC460CA051D29E5 /* Pods_Runner.framework in Frameworks */,
6571
);
6672
runOnlyForDeploymentPostprocessing = 0;
6773
};
6874
/* End PBXFrameworksBuildPhase section */
6975

7076
/* Begin PBXGroup section */
77+
0D3E478BAA88EA793F9EFF9B /* Pods */ = {
78+
isa = PBXGroup;
79+
children = (
80+
C77E02D8A7E5743EE4395169 /* Pods-Runner.debug.xcconfig */,
81+
4E85868E43666D91678AA906 /* Pods-Runner.release.xcconfig */,
82+
DB04B01663E9E9EC2B4EF6FF /* Pods-Runner.profile.xcconfig */,
83+
);
84+
name = Pods;
85+
path = Pods;
86+
sourceTree = "<group>";
87+
};
7188
331C8082294A63A400263BE5 /* RunnerTests */ = {
7289
isa = PBXGroup;
7390
children = (
@@ -94,6 +111,8 @@
94111
97C146F01CF9000F007C117D /* Runner */,
95112
97C146EF1CF9000F007C117D /* Products */,
96113
331C8082294A63A400263BE5 /* RunnerTests */,
114+
0D3E478BAA88EA793F9EFF9B /* Pods */,
115+
9CD7D48BCEEB070AFC1263A2 /* Frameworks */,
97116
);
98117
sourceTree = "<group>";
99118
};
@@ -121,6 +140,14 @@
121140
path = Runner;
122141
sourceTree = "<group>";
123142
};
143+
9CD7D48BCEEB070AFC1263A2 /* Frameworks */ = {
144+
isa = PBXGroup;
145+
children = (
146+
8C00575E57111313065C9F9B /* Pods_Runner.framework */,
147+
);
148+
name = Frameworks;
149+
sourceTree = "<group>";
150+
};
124151
/* End PBXGroup section */
125152

126153
/* Begin PBXNativeTarget section */
@@ -145,12 +172,14 @@
145172
isa = PBXNativeTarget;
146173
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
147174
buildPhases = (
175+
60E42B1B857F2D5CEDD1379F /* [CP] Check Pods Manifest.lock */,
148176
9740EEB61CF901F6004384FC /* Run Script */,
149177
97C146EA1CF9000F007C117D /* Sources */,
150178
97C146EB1CF9000F007C117D /* Frameworks */,
151179
97C146EC1CF9000F007C117D /* Resources */,
152180
9705A1C41CF9048500538489 /* Embed Frameworks */,
153181
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
182+
E7ED4D797A3AECC834B9126D /* [CP] Embed Pods Frameworks */,
154183
);
155184
buildRules = (
156185
);
@@ -238,6 +267,28 @@
238267
shellPath = /bin/sh;
239268
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
240269
};
270+
60E42B1B857F2D5CEDD1379F /* [CP] Check Pods Manifest.lock */ = {
271+
isa = PBXShellScriptBuildPhase;
272+
buildActionMask = 2147483647;
273+
files = (
274+
);
275+
inputFileListPaths = (
276+
);
277+
inputPaths = (
278+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
279+
"${PODS_ROOT}/Manifest.lock",
280+
);
281+
name = "[CP] Check Pods Manifest.lock";
282+
outputFileListPaths = (
283+
);
284+
outputPaths = (
285+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
286+
);
287+
runOnlyForDeploymentPostprocessing = 0;
288+
shellPath = /bin/sh;
289+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
290+
showEnvVarsInLog = 0;
291+
};
241292
9740EEB61CF901F6004384FC /* Run Script */ = {
242293
isa = PBXShellScriptBuildPhase;
243294
alwaysOutOfDate = 1;
@@ -253,6 +304,23 @@
253304
shellPath = /bin/sh;
254305
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
255306
};
307+
E7ED4D797A3AECC834B9126D /* [CP] Embed Pods Frameworks */ = {
308+
isa = PBXShellScriptBuildPhase;
309+
buildActionMask = 2147483647;
310+
files = (
311+
);
312+
inputFileListPaths = (
313+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
314+
);
315+
name = "[CP] Embed Pods Frameworks";
316+
outputFileListPaths = (
317+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
318+
);
319+
runOnlyForDeploymentPostprocessing = 0;
320+
shellPath = /bin/sh;
321+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
322+
showEnvVarsInLog = 0;
323+
};
256324
/* End PBXShellScriptBuildPhase section */
257325

258326
/* Begin PBXSourcesBuildPhase section */

example/ios/Runner.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/main.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MyHomePage extends StatefulWidget {
2626

2727
class MyHomePageState extends State<MyHomePage> {
2828
final _formKey = GlobalKey<FormBuilderState>();
29-
bool _useCustomFileViewer = true;
29+
bool _useCustomFileViewer = false;
3030

3131
@override
3232
Widget build(BuildContext context) {
@@ -69,6 +69,12 @@ class MyHomePageState extends State<MyHomePage> {
6969
? (files, filesSetter) =>
7070
customFileViewerBuilder(files ?? [], (newValue) {})
7171
: null,
72+
onDefaultViewerItemTap:
73+
_useCustomFileViewer
74+
? null
75+
: (PlatformFile file, int index) {
76+
debugPrint(file.name);
77+
},
7278
),
7379
const SizedBox(height: 20),
7480
Row(
@@ -81,20 +87,18 @@ class MyHomePageState extends State<MyHomePage> {
8187
debugPrint(_formKey.currentState!.value.toString());
8288
},
8389
),
84-
const Spacer(),
8590
ElevatedButton(
8691
child: Text(
8792
_useCustomFileViewer
88-
? 'Use Default File Viewer'
89-
: 'Use Custom File Viewer',
93+
? 'Use Default Viewer'
94+
: 'Use Custom Viewer',
9095
),
9196
onPressed: () {
9297
setState(
9398
() => _useCustomFileViewer = !_useCustomFileViewer,
9499
);
95100
},
96101
),
97-
const Spacer(),
98102
ElevatedButton(
99103
child: const Text('Reset'),
100104
onPressed: () {

lib/src/form_builder_file_picker.dart

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ typedef FileViewerBuilder =
2020
FormFieldSetter<List<PlatformFile>> filesSetter,
2121
);
2222

23+
typedef OnDefaultFileViewerBuilderItemTap =
24+
void Function(PlatformFile file, int index);
25+
2326
class TypeSelector {
2427
final FileType type;
2528
final Widget selector;
@@ -77,6 +80,9 @@ class FormBuilderFilePicker
7780
/// Allow to customise the view of the pickers.
7881
final Widget Function(List<Widget> types)? customTypeViewerBuilder;
7982

83+
/// Allow to set file tap functionality callback
84+
final OnDefaultFileViewerBuilderItemTap? onDefaultViewerItemTap;
85+
8086
/// Creates field for image(s) from user device storage
8187
FormBuilderFilePicker({
8288
//From Super
@@ -110,6 +116,7 @@ class FormBuilderFilePicker
110116
this.compressionQuality = 0,
111117
this.customFileViewerBuilder,
112118
this.customTypeViewerBuilder,
119+
this.onDefaultViewerItemTap,
113120
}) : super(
114121
builder: (FormFieldState<List<PlatformFile>?> field) {
115122
final state = field as _FormBuilderFilePickerState;
@@ -143,6 +150,7 @@ class FormBuilderFilePicker
143150
: state.defaultFileViewer(
144151
state._files,
145152
(files) => state._setFiles(files ?? [], field),
153+
onDefaultViewerItemTap,
146154
),
147155
],
148156
),
@@ -238,6 +246,7 @@ class _FormBuilderFilePickerState
238246
Widget defaultFileViewer(
239247
List<PlatformFile> files,
240248
FormFieldSetter<List<PlatformFile>> setter,
249+
OnDefaultFileViewerBuilderItemTap? onItemTap,
241250
) {
242251
final theme = Theme.of(context);
243252

@@ -260,31 +269,38 @@ class _FormBuilderFilePickerState
260269
child: Stack(
261270
alignment: Alignment.bottomCenter,
262271
children: <Widget>[
263-
Container(
264-
alignment: Alignment.center,
265-
child:
266-
(imageFileExts.contains(
267-
files[index].extension!.toLowerCase(),
268-
) &&
269-
widget.previewImages)
270-
? widget.withData
271-
? Image.memory(
272-
files[index].bytes!,
273-
fit: BoxFit.cover,
274-
)
275-
: Image.file(
276-
File(files[index].path!),
277-
fit: BoxFit.cover,
278-
)
279-
: Container(
280-
alignment: Alignment.center,
281-
color: theme.primaryColor,
282-
child: Icon(
283-
getIconData(files[index].extension!),
284-
color: Colors.white,
285-
size: 56,
272+
InkWell(
273+
onTap: () {
274+
if (onItemTap != null) {
275+
onItemTap(files[index], index);
276+
}
277+
},
278+
child: Container(
279+
alignment: Alignment.center,
280+
child:
281+
(imageFileExts.contains(
282+
files[index].extension!.toLowerCase(),
283+
) &&
284+
widget.previewImages)
285+
? widget.withData
286+
? Image.memory(
287+
files[index].bytes!,
288+
fit: BoxFit.cover,
289+
)
290+
: Image.file(
291+
File(files[index].path!),
292+
fit: BoxFit.cover,
293+
)
294+
: Container(
295+
alignment: Alignment.center,
296+
color: theme.primaryColor,
297+
child: Icon(
298+
getIconData(files[index].extension!),
299+
color: Colors.white,
300+
size: 56,
301+
),
286302
),
287-
),
303+
),
288304
),
289305
Container(
290306
padding: const EdgeInsets.symmetric(horizontal: 2),

0 commit comments

Comments
 (0)