@@ -34,6 +34,7 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
3434 Future <Map <String ,dynamic >> _albumsFuture;
3535 Future <Map <String ,dynamic >> _imagesFuture;
3636
37+ bool _canUpload = false ;
3738 bool _isEditMode;
3839 int _page;
3940 int _nbImages;
@@ -76,7 +77,6 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
7677 imageList.addAll (newListPage);
7778 }
7879 setState (() {
79- print ('Fetch images of page $_page ' );
8080 _getData ();
8181 });
8282 }
@@ -296,13 +296,15 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
296296
297297 handleAlbumSnapshot (AsyncSnapshot albumSnapshot, int nbImages) {
298298 var albums = albumSnapshot.data['result' ]['categories' ];
299- int nbImages = _nbImages;
300- if (albums.length > 0 && albums[0 ]["id" ].toString () == widget.category) {
301- nbImages = albums[0 ]["total_nb_images" ];
302- _nbImages = nbImages;
299+ if (albums.length > 0 && albums.first["id" ].toString () == widget.category) {
300+ _nbImages = albums.first["total_nb_images" ];
301+ _canUpload = albums.first["can_upload" ] ?? false ;
302+ WidgetsBinding .instance.addPostFrameCallback ((timeStamp) {
303+ setState (() {});
304+ });
303305 }
304306 albums.removeWhere ((category) =>
305- (category["id" ].toString () == widget.category)
307+ (category["id" ].toString () == widget.category)
306308 );
307309 return albums;
308310 }
@@ -439,81 +441,79 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
439441 });
440442 },
441443 ),
442- SpeedDialChild (
443- elevation: 5 ,
444- labelWidget: Text (appStrings (context).categoryUpload_images, style: TextStyle (fontSize: 14 , fontWeight: FontWeight .bold, color: Colors .white)),
445- child: Icon (Icons .add_to_photos),
446- backgroundColor: _theme.floatingActionButtonTheme.backgroundColor,
447- foregroundColor: _theme.floatingActionButtonTheme.foregroundColor,
448- onTap: () async {
449- try {
450- ScaffoldMessenger .of (context).removeCurrentSnackBar ();
451- ScaffoldMessenger .of (context).showSnackBar (SnackBar (
452- content: Row (
453- mainAxisAlignment: MainAxisAlignment .spaceBetween,
454- mainAxisSize: MainAxisSize .min,
455- children: [
456- Text (appStrings (context).loadingHUD_label),
457- CircularProgressIndicator (),
458- ],
459- ),
460- duration: Duration (days: 365 ),
461- ));
462- final List <XFile > images = ((await FilePicker .platform.pickFiles (
463- type: FileType .media,
464- allowMultiple: true ,
465- )) ? .files ?? []).map <XFile >((e) => XFile (e.path, name: e.name, bytes: e.bytes)).toList ();
466- ScaffoldMessenger .of (context).removeCurrentSnackBar ();
467- if (images.isNotEmpty) {
468- Navigator .push (context, MaterialPageRoute (
469- builder: (context) => UploadGalleryViewPage (imageData: images, category: widget.category)
470- )).whenComplete (() {
471- setState (() {
472- print ('After upload' ); // refresh
473- });
474- });
444+ if (_canUpload) ... [
445+ SpeedDialChild (
446+ elevation: 5 ,
447+ labelWidget: Text (appStrings (context).categoryUpload_images, style: TextStyle (fontSize: 14 , fontWeight: FontWeight .bold, color: Colors .white)),
448+ child: Icon (Icons .add_to_photos),
449+ backgroundColor: _theme.floatingActionButtonTheme.backgroundColor,
450+ foregroundColor: _theme.floatingActionButtonTheme.foregroundColor,
451+ onTap: () async {
452+ try {
453+ ScaffoldMessenger .of (context).removeCurrentSnackBar ();
454+ ScaffoldMessenger .of (context).showSnackBar (SnackBar (
455+ content: Row (
456+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
457+ mainAxisSize: MainAxisSize .min,
458+ children: [
459+ Text (appStrings (context).loadingHUD_label),
460+ CircularProgressIndicator (),
461+ ],
462+ ),
463+ duration: Duration (days: 365 ),
464+ ));
465+ final List <XFile > images = ((await FilePicker .platform.pickFiles (
466+ type: FileType .media,
467+ allowMultiple: true ,
468+ )) ? .files ?? []).map <XFile >((e) => XFile (e.path, name: e.name, bytes: e.bytes)).toList ();
469+ ScaffoldMessenger .of (context).removeCurrentSnackBar ();
470+ if (images.isNotEmpty) {
471+ Navigator .push (context, MaterialPageRoute (
472+ builder: (context) => UploadGalleryViewPage (imageData: images, category: widget.category)
473+ )).whenComplete (() {
474+ setState (() {});
475+ });
476+ }
477+ } catch (e) {
478+ debugPrint ('${e .toString ()}' );
479+ }
475480 }
476- } catch (e) {
477- print ('${e .toString ()}' );
478- }
479- }
480- ),
481- SpeedDialChild (
482- elevation: 5 ,
483- labelWidget: Text (appStrings (context).categoryUpload_take, style: TextStyle (fontSize: 14 , fontWeight: FontWeight .bold, color: Colors .white)),
484- child: Icon (Icons .photo_camera_rounded),
485- backgroundColor: _theme.floatingActionButtonTheme.backgroundColor,
486- foregroundColor: _theme.floatingActionButtonTheme.foregroundColor,
487- onTap: () async {
488- try {
489- ScaffoldMessenger .of (context).removeCurrentSnackBar ();
490- ScaffoldMessenger .of (context).showSnackBar (SnackBar (
491- content: Row (
492- mainAxisAlignment: MainAxisAlignment .spaceBetween,
493- mainAxisSize: MainAxisSize .min,
494- children: [
495- Text (appStrings (context).loadingHUD_label),
496- CircularProgressIndicator (),
497- ],
498- ),
499- duration: Duration (days: 365 ),
500- ));
501- final XFile image = await ImagePicker ().pickImage (source: ImageSource .camera);
502- ScaffoldMessenger .of (context).removeCurrentSnackBar ();
503- if (image != null ) {
504- Navigator .push (context, MaterialPageRoute (
505- builder: (context) => UploadGalleryViewPage (imageData: [image], category: widget.category)
506- )).whenComplete (() {
507- setState (() {
508- print ('After upload' ); // refresh
481+ ),
482+ SpeedDialChild (
483+ elevation: 5 ,
484+ labelWidget: Text (appStrings (context).categoryUpload_take, style: TextStyle (fontSize: 14 , fontWeight: FontWeight .bold, color: Colors .white)),
485+ child: Icon (Icons .photo_camera_rounded),
486+ backgroundColor: _theme.floatingActionButtonTheme.backgroundColor,
487+ foregroundColor: _theme.floatingActionButtonTheme.foregroundColor,
488+ onTap: () async {
489+ try {
490+ ScaffoldMessenger .of (context).removeCurrentSnackBar ();
491+ ScaffoldMessenger .of (context).showSnackBar (SnackBar (
492+ content: Row (
493+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
494+ mainAxisSize: MainAxisSize .min,
495+ children: [
496+ Text (appStrings (context).loadingHUD_label),
497+ CircularProgressIndicator (),
498+ ],
499+ ),
500+ duration: Duration (days: 365 ),
501+ ));
502+ final XFile image = await ImagePicker ().pickImage (source: ImageSource .camera);
503+ ScaffoldMessenger .of (context).removeCurrentSnackBar ();
504+ if (image != null ) {
505+ Navigator .push (context, MaterialPageRoute (
506+ builder: (context) => UploadGalleryViewPage (imageData: [image], category: widget.category)
507+ )).whenComplete (() {
508+ setState (() {});
509509 });
510- });
510+ }
511+ } catch (e) {
512+ debugPrint ('Dio error ${e .toString ()}' );
511513 }
512- } catch (e) {
513- print ('Dio error ${e .toString ()}' );
514514 }
515- }
516- ) ,
515+ ),
516+ ] ,
517517 ],
518518 );
519519 }
@@ -541,7 +541,7 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
541541 itemBuilder: (BuildContext context, int index) {
542542 var album = albums[index];
543543 return AlbumListItem (album,
544- isAdmin: widget.isAdmin ,
544+ isAdmin: API .prefs. getString ( 'user_status' ) != 'normal' ,
545545 onClose: () {
546546 setState (() {
547547 _getData ();
@@ -694,14 +694,14 @@ class _CategoryViewPageState extends State<CategoryViewPage> with SingleTickerPr
694694 padding: const EdgeInsets .all (8.0 ),
695695 child: Stack (
696696 children: < Widget > [
697- widget.isAdmin? Align (
697+ widget.isAdmin || _canUpload ? Align (
698698 alignment: Alignment .bottomRight,
699699 child: _createUploadActionButton,
700- ) : Container (),
700+ ) : const SizedBox (),
701701 Align (
702702 alignment: Alignment .bottomRight,
703703 child: Container (
704- margin: EdgeInsets .only (bottom: 0 , right: widget.isAdmin? 70 : 0 ),
704+ margin: EdgeInsets .only (bottom: 0 , right: widget.isAdmin || _canUpload ? 70 : 0 ),
705705 child: FloatingActionButton (
706706 backgroundColor: Color (0xff868686 ),
707707 onPressed: () {
0 commit comments