From cc2f9dbb94f6407ba458aa601a60e109090dd7c4 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Thu, 29 Sep 2022 21:01:28 +0200 Subject: [PATCH] different border radius per device type and os larger tiles on tablets --- lib/full_screen_image_view.dart | 11 +++++++---- lib/image_grid.dart | 11 ++++------- lib/image_tile.dart | 21 +++++++++++++++------ lib/utils/tile_size.dart | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 lib/utils/tile_size.dart diff --git a/lib/full_screen_image_view.dart b/lib/full_screen_image_view.dart index 4aacbb5..bd8698f 100644 --- a/lib/full_screen_image_view.dart +++ b/lib/full_screen_image_view.dart @@ -46,13 +46,15 @@ class _FullScreenImageViewState extends State { scrollPhysics: const BouncingScrollPhysics(), builder: (BuildContext context, int index) { return PhotoViewGalleryPageOptions( - imageProvider: widget.provider.getImageProvider(widget.items[index].uri), + imageProvider: + widget.provider.getImageProvider(widget.items[index].uri), initialScale: PhotoViewComputedScale.contained, minScale: PhotoViewComputedScale.contained, - heroAttributes: PhotoViewHeroAttributes(tag: widget.items[index].name), + heroAttributes: + PhotoViewHeroAttributes(tag: widget.items[index].name), ); }, - itemCount: widget.items.length, + itemCount: widget.items.length, loadingBuilder: (context, event) => Center( child: SizedBox( width: 20.0, @@ -60,7 +62,8 @@ class _FullScreenImageViewState extends State { child: CircularProgressIndicator( value: event == null || event.expectedTotalBytes == null ? null - : event.cumulativeBytesLoaded / event.expectedTotalBytes!, + : event.cumulativeBytesLoaded / + event.expectedTotalBytes!, ), ), ), diff --git a/lib/image_grid.dart b/lib/image_grid.dart index b889ddf..db0950d 100644 --- a/lib/image_grid.dart +++ b/lib/image_grid.dart @@ -1,6 +1,5 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; +import 'package:gallery/utils/tile_size.dart'; import 'data_provider/data_provider.dart'; import 'full_screen_image_view.dart'; @@ -43,15 +42,13 @@ class _ImageGridState extends State { gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisSpacing: 0, mainAxisSpacing: 0, - crossAxisCount: - Platform.isAndroid ? width ~/ 100 : width ~/ 300, + crossAxisCount: width ~/ calcTileMaxWidth(), ), itemCount: data.items.length + 1, itemBuilder: (context, index) { if (index == 0) { return ImageTile( - child: Icon(Icons.arrow_back, - size: Platform.isAndroid ? 64 : 142), + child: Icon(Icons.arrow_back, size: calcTileMaxWidth() / 2), onClick: () { setState(() { folder = widget.dProvider.listOfFiles(uri: data.parent); @@ -98,7 +95,7 @@ class _ImageGridState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.folder_open, - size: Platform.isAndroid ? 64 : 142), + size: calcTileMaxWidth() / 2), Text(elem.name) ], ) diff --git a/lib/image_tile.dart b/lib/image_tile.dart index 81211d5..5bf557f 100644 --- a/lib/image_tile.dart +++ b/lib/image_tile.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:gallery/data_provider/data_provider.dart'; +import 'package:gallery/utils/tile_size.dart'; class ImageTile extends StatelessWidget { const ImageTile( @@ -17,24 +18,32 @@ class ImageTile extends StatelessWidget { onClick?.call(); }, child: Container( - padding: const EdgeInsets.all(5), + padding: const EdgeInsets.all(3), child: Container( decoration: imageUri == null - ? const BoxDecoration( + ? BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(10.0)), + borderRadius: BorderRadius.all( + Radius.circular(calcTileMaxWidth() / 30)), boxShadow: [ BoxShadow( color: Colors.black12, - spreadRadius: 2.0, - blurRadius: 5.0), + spreadRadius: calcTileMaxWidth() / 150, + blurRadius: calcTileMaxWidth() / 60), ]) : BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: dtaProvider!.getImageProvider(imageUri!), ), - ), + borderRadius: BorderRadius.all( + Radius.circular(calcTileMaxWidth() / 30)), + boxShadow: [ + BoxShadow( + color: Colors.black12, + spreadRadius: calcTileMaxWidth() / 150, + blurRadius: calcTileMaxWidth() / 60), + ]), child: child)), ); } diff --git a/lib/utils/tile_size.dart b/lib/utils/tile_size.dart new file mode 100644 index 0000000..c010b0f --- /dev/null +++ b/lib/utils/tile_size.dart @@ -0,0 +1,24 @@ +import 'dart:io'; + +import 'package:flutter/widgets.dart'; + +enum DeviceType { phone, tablet } + +DeviceType getDeviceType() { + final data = MediaQueryData.fromWindow(WidgetsBinding.instance.window); + return data.size.shortestSide < 550 ? DeviceType.phone : DeviceType.tablet; +} + +int calcTileMaxWidth() { + if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) { + return 300; + } else if (Platform.isAndroid || Platform.isIOS) { + if (getDeviceType() == DeviceType.tablet) { + return 150; + } else { + return 100; + } + } else { + return 250; + } +}