From 16c43b46c9d09328aa7ae0749f6fb9de03c07bd7 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 24 Jul 2019 00:36:32 +0900 Subject: [PATCH] use final where possible --- lib/common/draggable_scrollbar.dart | 2 +- lib/image_fullscreen_overlay.dart | 6 +++--- lib/image_fullscreen_page.dart | 4 ++-- lib/model/image_entry.dart | 6 +++--- lib/thumbnail.dart | 12 ++++++------ lib/thumbnail_collection.dart | 13 ++++++------- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/common/draggable_scrollbar.dart b/lib/common/draggable_scrollbar.dart index 8d2991a3b..a92061f41 100644 --- a/lib/common/draggable_scrollbar.dart +++ b/lib/common/draggable_scrollbar.dart @@ -128,7 +128,7 @@ class DraggableScrollbar extends StatefulWidget { _DraggableScrollbarState createState() => _DraggableScrollbarState(); static buildScrollThumbAndLabel({@required Widget scrollThumb, @required Color backgroundColor, @required Animation thumbAnimation, @required Animation labelAnimation, @required Text labelText, @required BoxConstraints labelConstraints, @required bool alwaysVisibleScrollThumb}) { - var scrollThumbAndLabel = labelText == null + final scrollThumbAndLabel = labelText == null ? scrollThumb : Row( mainAxisSize: MainAxisSize.min, diff --git a/lib/image_fullscreen_overlay.dart b/lib/image_fullscreen_overlay.dart index 94fb751f0..61f57203e 100644 --- a/lib/image_fullscreen_overlay.dart +++ b/lib/image_fullscreen_overlay.dart @@ -39,9 +39,9 @@ class _FullscreenOverlayState extends State { @override Widget build(BuildContext context) { - var viewInsets = MediaQuery.of(context).viewInsets; - var date = ImageEntry.getBestDate(entry); - var subRowConstraints = BoxConstraints(maxWidth: 400); + final viewInsets = MediaQuery.of(context).viewInsets; + final date = ImageEntry.getBestDate(entry); + final subRowConstraints = BoxConstraints(maxWidth: 400); return IgnorePointer( child: Container( padding: EdgeInsets.all(8.0).add(EdgeInsets.only(bottom: viewInsets.bottom)), diff --git a/lib/image_fullscreen_page.dart b/lib/image_fullscreen_page.dart index d341a8e89..3ca636a71 100644 --- a/lib/image_fullscreen_page.dart +++ b/lib/image_fullscreen_page.dart @@ -29,7 +29,7 @@ class ImageFullscreenPageState extends State { @override void initState() { super.initState(); - var index = entries.indexWhere((entry) => entry['uri'] == widget.initialUri); + final index = entries.indexWhere((entry) => entry['uri'] == widget.initialUri); _currentPage = max(0, index); _pageController = PageController(initialPage: _currentPage); } @@ -49,7 +49,7 @@ class ImageFullscreenPageState extends State { PhotoViewGallery.builder( itemCount: entries.length, builder: (context, index) { - var entry = entries[index]; + final entry = entries[index]; return PhotoViewGalleryPageOptions( imageProvider: FileImage(File(entry['path'])), heroTag: entry['uri'], diff --git a/lib/model/image_entry.dart b/lib/model/image_entry.dart index cdba25dce..de9d13d18 100644 --- a/lib/model/image_entry.dart +++ b/lib/model/image_entry.dart @@ -1,16 +1,16 @@ class ImageEntry { static DateTime getBestDate(Map entry) { - var dateTakenMillis = entry['sourceDateTakenMillis'] as int; + final dateTakenMillis = entry['sourceDateTakenMillis'] as int; if (dateTakenMillis != null && dateTakenMillis > 0) return DateTime.fromMillisecondsSinceEpoch(dateTakenMillis); - var dateModifiedSecs = entry['dateModifiedSecs'] as int; + final dateModifiedSecs = entry['dateModifiedSecs'] as int; if (dateModifiedSecs != null && dateModifiedSecs > 0) return DateTime.fromMillisecondsSinceEpoch(dateModifiedSecs * 1000); return null; } static DateTime getDayTaken(Map entry) { - var d = getBestDate(entry); + final d = getBestDate(entry); return d == null ? null : DateTime(d.year, d.month, d.day); } } diff --git a/lib/thumbnail.dart b/lib/thumbnail.dart index 6ebce746e..bc0b5fdc1 100644 --- a/lib/thumbnail.dart +++ b/lib/thumbnail.dart @@ -45,7 +45,7 @@ class ThumbnailState extends State { } initByteLoader() { - var dim = (widget.extent * widget.devicePixelRatio).round(); + final dim = (widget.extent * widget.devicePixelRatio).round(); _byteLoader = ImageFetcher.getImageBytes(widget.entry, dim, dim); } @@ -58,9 +58,9 @@ class ThumbnailState extends State { @override Widget build(BuildContext context) { - var isVideo = mimeType.startsWith(MimeTypes.MIME_VIDEO); - var isGif = mimeType == MimeTypes.MIME_GIF; - var iconSize = widget.extent / 4; + final isVideo = mimeType.startsWith(MimeTypes.MIME_VIDEO); + final isGif = mimeType == MimeTypes.MIME_GIF; + final iconSize = widget.extent / 4; return Container( decoration: BoxDecoration( border: Border.all( @@ -71,7 +71,7 @@ class ThumbnailState extends State { child: FutureBuilder( future: _byteLoader, builder: (futureContext, AsyncSnapshot snapshot) { - var bytes = (snapshot.connectionState == ConnectionState.done && !snapshot.hasError) ? snapshot.data : kTransparentImage; + final bytes = (snapshot.connectionState == ConnectionState.done && !snapshot.hasError) ? snapshot.data : kTransparentImage; return Stack( alignment: AlignmentDirectional.bottomStart, children: [ @@ -81,7 +81,7 @@ class ThumbnailState extends State { // during hero animation back from a fullscreen image, // the image covers the whole screen (because of the 'fit' prop and the full screen hero constraints) // so we wrap the image to apply better constraints - var dim = min(constraints.maxWidth, constraints.maxHeight); + final dim = min(constraints.maxWidth, constraints.maxHeight); return Container( alignment: Alignment.center, constraints: BoxConstraints.tight(Size(dim, dim)), diff --git a/lib/thumbnail_collection.dart b/lib/thumbnail_collection.dart index 8369a4954..090a29814 100644 --- a/lib/thumbnail_collection.dart +++ b/lib/thumbnail_collection.dart @@ -60,19 +60,18 @@ class SectionSliver extends StatelessWidget { @override Widget build(BuildContext context) { // debugPrint('$runtimeType build with sectionKey=$sectionKey'); - var columnCount = 4; - var mediaQuery = MediaQuery.of(context); - + final columnCount = 4; return SliverStickyHeader( header: DaySectionHeader(date: sectionKey), sliver: SliverGrid( delegate: SliverChildBuilderDelegate( - (context, index) { - var sectionEntries = sections[sectionKey]; + (sliverContext, index) { + final sectionEntries = sections[sectionKey]; if (index >= sectionEntries.length) return null; - var entry = sectionEntries[index]; + final entry = sectionEntries[index]; + final mediaQuery = MediaQuery.of(sliverContext); return GestureDetector( - onTap: () => _showFullscreen(context, entry), + onTap: () => _showFullscreen(sliverContext, entry), child: Thumbnail( entry: entry, extent: mediaQuery.size.width / columnCount,