kanweg_test_upload_widget.dart 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import '/flutter_flow/flutter_flow_theme.dart';
  2. import '/flutter_flow/flutter_flow_util.dart';
  3. import '/flutter_flow/flutter_flow_widgets.dart';
  4. import '/flutter_flow/upload_data.dart';
  5. import 'dart:ui';
  6. import '/custom_code/actions/index.dart' as actions;
  7. import 'package:flutter/material.dart';
  8. import 'package:flutter_spinkit/flutter_spinkit.dart';
  9. import 'package:google_fonts/google_fonts.dart';
  10. import 'package:provider/provider.dart';
  11. import 'kanweg_test_upload_model.dart';
  12. export 'kanweg_test_upload_model.dart';
  13. class KanwegTestUploadWidget extends StatefulWidget {
  14. const KanwegTestUploadWidget({super.key});
  15. static String routeName = 'kanwegTestUpload';
  16. static String routePath = '/kanwegTestUpload';
  17. @override
  18. State<KanwegTestUploadWidget> createState() => _KanwegTestUploadWidgetState();
  19. }
  20. class _KanwegTestUploadWidgetState extends State<KanwegTestUploadWidget>
  21. with RouteAware {
  22. late KanwegTestUploadModel _model;
  23. final scaffoldKey = GlobalKey<ScaffoldState>();
  24. @override
  25. void initState() {
  26. super.initState();
  27. _model = createModel(context, () => KanwegTestUploadModel());
  28. }
  29. @override
  30. void dispose() {
  31. routeObserver.unsubscribe(this);
  32. _model.dispose();
  33. super.dispose();
  34. }
  35. @override
  36. void didUpdateWidget(KanwegTestUploadWidget oldWidget) {
  37. super.didUpdateWidget(oldWidget);
  38. _model.widget = widget;
  39. }
  40. @override
  41. void didChangeDependencies() {
  42. super.didChangeDependencies();
  43. final route = DebugModalRoute.of(context);
  44. if (route != null) {
  45. routeObserver.subscribe(this, route);
  46. }
  47. debugLogGlobalProperty(context);
  48. }
  49. @override
  50. void didPopNext() {
  51. if (mounted && DebugFlutterFlowModelContext.maybeOf(context) == null) {
  52. setState(() => _model.isRouteVisible = true);
  53. debugLogWidgetClass(_model);
  54. }
  55. }
  56. @override
  57. void didPush() {
  58. if (mounted && DebugFlutterFlowModelContext.maybeOf(context) == null) {
  59. setState(() => _model.isRouteVisible = true);
  60. debugLogWidgetClass(_model);
  61. }
  62. }
  63. @override
  64. void didPop() {
  65. _model.isRouteVisible = false;
  66. }
  67. @override
  68. void didPushNext() {
  69. _model.isRouteVisible = false;
  70. }
  71. @override
  72. Widget build(BuildContext context) {
  73. DebugFlutterFlowModelContext.maybeOf(context)
  74. ?.parentModelCallback
  75. ?.call(_model);
  76. context.watch<FFAppState>();
  77. return GestureDetector(
  78. onTap: () {
  79. FocusScope.of(context).unfocus();
  80. FocusManager.instance.primaryFocus?.unfocus();
  81. },
  82. child: Scaffold(
  83. key: scaffoldKey,
  84. backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
  85. body: SafeArea(
  86. top: true,
  87. child: Column(
  88. mainAxisSize: MainAxisSize.max,
  89. children: [
  90. FFButtonWidget(
  91. onPressed: () async {
  92. final selectedMedia = await selectMediaWithSourceBottomSheet(
  93. context: context,
  94. allowPhoto: true,
  95. );
  96. if (selectedMedia != null &&
  97. selectedMedia.every(
  98. (m) => validateFileFormat(m.storagePath, context))) {
  99. safeSetState(
  100. () => _model.isDataUploading_uploadDataCnm = true);
  101. var selectedUploadedFiles = <FFUploadedFile>[];
  102. try {
  103. selectedUploadedFiles = selectedMedia
  104. .map((m) => FFUploadedFile(
  105. name: m.storagePath.split('/').last,
  106. bytes: m.bytes,
  107. height: m.dimensions?.height,
  108. width: m.dimensions?.width,
  109. blurHash: m.blurHash,
  110. originalFilename: m.originalFilename,
  111. ))
  112. .toList();
  113. } finally {
  114. _model.isDataUploading_uploadDataCnm = false;
  115. }
  116. if (selectedUploadedFiles.length == selectedMedia.length) {
  117. safeSetState(() {
  118. _model.uploadedLocalFile_uploadDataCnm =
  119. selectedUploadedFiles.first;
  120. });
  121. } else {
  122. safeSetState(() {});
  123. return;
  124. }
  125. }
  126. _model.uploadResult = await actions.bestandUpload(
  127. _model.uploadedLocalFile_uploadDataCnm,
  128. 'https://uitgaanskrant.com/en/flutterdrup/bestand_upload/upload.json',
  129. FFAppState().userSessionname,
  130. FFAppState().userSessionid,
  131. FFAppState().userToken,
  132. );
  133. ScaffoldMessenger.of(context).showSnackBar(
  134. SnackBar(
  135. content: Text(
  136. getJsonField(
  137. _model.uploadResult,
  138. r'''$''',
  139. ).toString(),
  140. style: TextStyle(
  141. color: FlutterFlowTheme.of(context).primaryText,
  142. ),
  143. ),
  144. duration: Duration(milliseconds: 8000),
  145. backgroundColor: FlutterFlowTheme.of(context).secondary,
  146. ),
  147. );
  148. safeSetState(() {});
  149. },
  150. text: FFLocalizations.of(context).getText(
  151. 'mw7suah8' /* Test Upload */,
  152. ),
  153. options: FFButtonOptions(
  154. height: 40.0,
  155. padding: EdgeInsetsDirectional.fromSTEB(16.0, 0.0, 16.0, 0.0),
  156. iconPadding:
  157. EdgeInsetsDirectional.fromSTEB(0.0, 0.0, 0.0, 0.0),
  158. color: FlutterFlowTheme.of(context).primary,
  159. textStyle: FlutterFlowTheme.of(context).titleSmall.override(
  160. font: GoogleFonts.interTight(
  161. fontWeight: FlutterFlowTheme.of(context)
  162. .titleSmall
  163. .fontWeight,
  164. fontStyle:
  165. FlutterFlowTheme.of(context).titleSmall.fontStyle,
  166. ),
  167. color: Colors.white,
  168. letterSpacing: 0.0,
  169. fontWeight:
  170. FlutterFlowTheme.of(context).titleSmall.fontWeight,
  171. fontStyle:
  172. FlutterFlowTheme.of(context).titleSmall.fontStyle,
  173. ),
  174. elevation: 0.0,
  175. borderRadius: BorderRadius.circular(8.0),
  176. ),
  177. ),
  178. ],
  179. ),
  180. ),
  181. ),
  182. );
  183. }
  184. }