From 22a6f9f06398b2bd4b258c3e1d2eb38313081bde Mon Sep 17 00:00:00 2001 From: TiBo Date: Fri, 29 Mar 2024 10:07:53 +0100 Subject: [PATCH] style: fixing some lint issues - apply lint - add const when needed - fix misspelling issue - remove unnecessary `new` keyword --- lib/component/collection_preview.dart | 31 ++-- lib/component/loader.dart | 5 +- lib/main.dart | 2 +- lib/page/capture_page.dart | 201 +++++++++++++------------- lib/page/homepage.dart | 107 +++++++------- lib/service/api/model/geo_visio.dart | 5 +- 6 files changed, 166 insertions(+), 185 deletions(-) diff --git a/lib/component/collection_preview.dart b/lib/component/collection_preview.dart index 34653cd..416fddc 100644 --- a/lib/component/collection_preview.dart +++ b/lib/component/collection_preview.dart @@ -7,12 +7,12 @@ class CollectionPreview extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - margin: EdgeInsets.all(10), + margin: const EdgeInsets.all(10), height: 230, width: double.infinity, decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.all( + borderRadius: const BorderRadius.all( Radius.circular(18), ), boxShadow: [ @@ -20,7 +20,7 @@ class CollectionPreview extends StatelessWidget { color: Colors.grey.shade200, spreadRadius: 4, blurRadius: 6, - offset: Offset(0, 3), + offset: const Offset(0, 3), ), ], ), @@ -29,7 +29,7 @@ class CollectionPreview extends StatelessWidget { Container( height: 140, decoration: BoxDecoration( - borderRadius: BorderRadius.only( + borderRadius: const BorderRadius.only( topLeft: Radius.circular(18), topRight: Radius.circular(18), ), @@ -45,9 +45,9 @@ class CollectionPreview extends StatelessWidget { right: -15, child: MaterialButton( color: Colors.white, - shape: CircleBorder(), + shape: const CircleBorder(), onPressed: () {}, - child: Icon( + child: const Icon( Icons.edit_rounded, size: 20, ), @@ -57,7 +57,7 @@ class CollectionPreview extends StatelessWidget { ), ), Container( - margin: EdgeInsets.fromLTRB(10, 10, 10, 0), + margin: const EdgeInsets.fromLTRB(10, 10, 10, 0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -72,7 +72,7 @@ class CollectionPreview extends StatelessWidget { ), ), Container( - margin: EdgeInsets.symmetric(horizontal: 10), + margin: const EdgeInsets.symmetric(horizontal: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -88,22 +88,20 @@ class CollectionPreview extends StatelessWidget { ), ), Container( - margin: EdgeInsets.fromLTRB(10, 3, 10, 0), + margin: const EdgeInsets.fromLTRB(10, 3, 10, 0), child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Text( DateFormat(DATE_FORMATTER).format(DateTime.parse( - collection.updated != null ? - collection.updated! : - collection.created - )), + collection.updated != null + ? collection.updated! + : collection.created)), style: GoogleFonts.nunito( fontSize: 14, color: Colors.grey[500], fontWeight: FontWeight.w400, - ) - ) + )) ], ), ), @@ -111,5 +109,4 @@ class CollectionPreview extends StatelessWidget { ), ); } - -} \ No newline at end of file +} diff --git a/lib/component/loader.dart b/lib/component/loader.dart index 79339ae..b1ef9ce 100644 --- a/lib/component/loader.dart +++ b/lib/component/loader.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:loading_animation_widget/loading_animation_widget.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../constant.dart'; class Loader extends StatelessWidget { @@ -16,8 +15,8 @@ class Loader extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - color: this.shadowBackground ? - Color.fromRGBO(0, 0, 0, 50) : + color: shadowBackground ? + const Color.fromRGBO(0, 0, 0, 50) : Colors.transparent , child: Column( diff --git a/lib/main.dart b/lib/main.dart index 0e93e96..c8e613d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,7 +30,7 @@ part 'service/routing.dart'; part 'service/permission_helper.dart'; -final String DATE_FORMATTER = 'dd/MM/y HH:mm:ss'; +const String DATE_FORMATTER = 'dd/MM/y HH:mm:ss'; void main() { runApp(const PanoramaxApp()); diff --git a/lib/page/capture_page.dart b/lib/page/capture_page.dart index 4827b31..9f041e6 100644 --- a/lib/page/capture_page.dart +++ b/lib/page/capture_page.dart @@ -26,11 +26,11 @@ class _CapturePageState extends State { super.initState(); if (widget.cameras?.isNotEmpty ?? false) { - initCamera(widget.cameras![0]); + initCamera(widget.cameras![0]); } } - void goToCollectionCreationPage(){ + void goToCollectionCreationPage() { context.push(Routes.newSequenceSend, extra: _imgListCaptured); } @@ -46,10 +46,12 @@ class _CapturePageState extends State { } try { if (await PermissionHelper.isPermissionGranted()) { - await Future.wait([ - getPictureFromCamera(), - Geolocator.getCurrentPosition() - ]).then((value) async { + await Future.wait( + [ + getPictureFromCamera(), + Geolocator.getCurrentPosition(), + ], + ).then((value) async { final XFile rawImage = value[0] as XFile; final Position currentLocation = value[1] as Position; await addExifTags(rawImage, currentLocation); @@ -87,8 +89,11 @@ class _CapturePageState extends State { } Future initCamera(CameraDescription cameraDescription) async { - _cameraController = - CameraController(cameraDescription, ResolutionPreset.high, enableAudio: false); + _cameraController = CameraController( + cameraDescription, + ResolutionPreset.high, + enableAudio: false, + ); try { await _cameraController.initialize().then((_) { if (!mounted) return; @@ -112,131 +117,121 @@ class _CapturePageState extends State { } var height = MediaQuery.of(context).size.height * 0.12; var cartIcon = IconButton( - onPressed: () { - }, + onPressed: () {}, iconSize: 30, padding: EdgeInsets.zero, constraints: const BoxConstraints(), icon: const Icon(Icons.add_shopping_cart_outlined, color: Colors.white), ); return Stack( - children: [ - cameraPreview(), - captureButton(height, context), - Positioned( - bottom: 0, - left: 0, - child: Container( - width: MediaQuery.of(context).size.width, - height: height, - decoration: const BoxDecoration(color: Colors.black), - child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [ - switchCameraButton(context), - imageCart(cartIcon), - createSequenceButton(context), - ]), - ) + children: [ + cameraPreview(), + captureButton(height, context), + Positioned( + bottom: 0, + left: 0, + child: Container( + width: MediaQuery.of(context).size.width, + height: height, + decoration: const BoxDecoration(color: Colors.black), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + switchCameraButton(context), + imageCart(cartIcon), + createSequenceButton(context), + ], ), - if(_isProcessing) processingLoader(context) - ] - ); + ), + ), + if (_isProcessing) processingLoader(context) + ], + ); } Expanded switchCameraButton(BuildContext context) { return Expanded( - child: IconButton( - padding: EdgeInsets.zero, - iconSize: 30, - icon: Icon( - _isRearCameraSelected - ? CupertinoIcons.switch_camera - : CupertinoIcons.switch_camera_solid, - color: Colors.white), - onPressed: () { - setState( - () => _isRearCameraSelected = !_isRearCameraSelected); - initCamera(widget.cameras![_isRearCameraSelected ? 0 : 1]); - }, - tooltip: AppLocalizations.of(context)!.switchCamera - ) - ); + child: IconButton( + padding: EdgeInsets.zero, + iconSize: 30, + icon: Icon(_isRearCameraSelected ? CupertinoIcons.switch_camera : CupertinoIcons.switch_camera_solid, + color: Colors.white), + onPressed: () { + setState(() => _isRearCameraSelected = !_isRearCameraSelected); + initCamera(widget.cameras![_isRearCameraSelected ? 0 : 1]); + }, + tooltip: AppLocalizations.of(context)!.switchCamera), + ); } Expanded createSequenceButton(BuildContext context) { return Expanded( - child: IconButton( - padding: EdgeInsets.zero, - iconSize: 30, - icon: const Icon( - Icons.send_outlined, - color: Colors.white - ), - onPressed: goToCollectionCreationPage, - tooltip: AppLocalizations.of(context)!.createSequenceWithPicture_tooltip - ) - ); + child: IconButton( + padding: EdgeInsets.zero, + iconSize: 30, + icon: const Icon(Icons.send_outlined, color: Colors.white), + onPressed: goToCollectionCreationPage, + tooltip: AppLocalizations.of(context)!.createSequenceWithPicture_tooltip)); } Widget imageCart(IconButton cartIcon) { - return _imgListCaptured.isNotEmpty ? - badges.Badge( - badgeContent: Text('${_imgListCaptured.length}'), - child: cartIcon, - ): - cartIcon; + return _imgListCaptured.isNotEmpty + ? badges.Badge( + badgeContent: Text('${_imgListCaptured.length}'), + child: cartIcon, + ) + : cartIcon; } Positioned captureButton(double height, BuildContext context) { return Positioned( - bottom: height, - left: 0, - child: Container( - width: MediaQuery.of(context).size.width, - height: height, - decoration: const BoxDecoration(color: Colors.transparent), - child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [ - Expanded( - child: IconButton( - onPressed: takePicture, - iconSize: 100, - padding: EdgeInsets.zero, - constraints: const BoxConstraints(), - icon: const Icon(Icons.circle_outlined, color: Colors.white), - tooltip: AppLocalizations.of(context)!.capture - )), - ]), - ) - ); + bottom: height, + left: 0, + child: Container( + width: MediaQuery.of(context).size.width, + height: height, + decoration: const BoxDecoration(color: Colors.transparent), + child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [ + Expanded( + child: IconButton( + onPressed: takePicture, + iconSize: 100, + padding: EdgeInsets.zero, + constraints: const BoxConstraints(), + icon: const Icon(Icons.circle_outlined, color: Colors.white), + tooltip: AppLocalizations.of(context)!.capture), + ), + ]), + )); } StatelessWidget cameraPreview() { return _cameraController.value.isInitialized - ? CameraPreview(_cameraController) - : Container( - color: Colors.transparent, - child: const Center(child: CircularProgressIndicator() - ) - ); + ? CameraPreview(_cameraController) + : Container( + color: Colors.transparent, + child: const Center(child: CircularProgressIndicator()), + ); } Positioned processingLoader(BuildContext context) { return Positioned( - top: 0, - bottom: 0, - left: 0, - right: 0, - child: Loader( - message: DefaultTextStyle( - style: Theme.of(context).textTheme.bodyLarge!, - child: Text( - AppLocalizations.of(context)!.waitDuringProcessing, - style: const TextStyle( - color: Colors.white, - ), - ), + top: 0, + bottom: 0, + left: 0, + right: 0, + child: Loader( + message: DefaultTextStyle( + style: Theme.of(context).textTheme.bodyLarge!, + child: Text( + AppLocalizations.of(context)!.waitDuringProcessing, + style: const TextStyle( + color: Colors.white, ), - shadowBackground: true - ) + ), + ), + shadowBackground: true, + ), ); } -} \ No newline at end of file +} diff --git a/lib/page/homepage.dart b/lib/page/homepage.dart index 241b2a4..bc46c4e 100644 --- a/lib/page/homepage.dart +++ b/lib/page/homepage.dart @@ -39,56 +39,57 @@ class _HomePageState extends State { if (!await PermissionHelper.isPermissionGranted()) { await PermissionHelper.askMissingPermission(); } - await availableCameras().then((availableCameras) => - context.push(Routes.newSequenceCapture, extra: availableCameras) + await availableCameras().then( + (availableCameras) => context.push(Routes.newSequenceCapture, extra: availableCameras), ); } - + Widget displayBody(isLoading) { - if(isLoading) - return LoaderIndicatorView(); - else if(geoVisionCollections == null) - return UnkownErrorView(); - else if(geoVisionCollections!.collections.length != 0) + if (isLoading) { + return const LoaderIndicatorView(); + } else if (geoVisionCollections == null) { + return const UnknownErrorView(); + } else if (geoVisionCollections!.collections.isNotEmpty) { return CollectionListView(collections: geoVisionCollections!.collections); - else - return NoElementView(); + } else { + return const NoElementView(); + } } @override Widget build(BuildContext context) { return RefreshIndicator( - displacement: 250, - strokeWidth: 3, - triggerMode: RefreshIndicatorTriggerMode.onEdge, - onRefresh: () async { - setState(() { - getCollections(); - }); - }, - child: Scaffold( - appBar: PanoramaxAppBar(context: context), + displacement: 250, + strokeWidth: 3, + triggerMode: RefreshIndicatorTriggerMode.onEdge, + onRefresh: () async { + setState(() { + getCollections(); + }); + }, + child: Scaffold( + appBar: PanoramaxAppBar(context: context), body: Column( - children: [ - Container( - margin: const EdgeInsets.fromLTRB(10, 10, 10, 10), - child: Semantics( - header: true, + children: [ + Container( + margin: const EdgeInsets.fromLTRB(10, 10, 10, 10), + child: Semantics( + header: true, child: Text(AppLocalizations.of(context)!.yourSequence, style: GoogleFonts.nunito(fontSize: 25, fontWeight: FontWeight.w400)), - ), + ), ), Expanded( child: displayBody(isLoading), - ), - ], ), - floatingActionButton: FloatingActionButton( - onPressed: _createCollection, - tooltip: AppLocalizations.of(context)!.createSequence_tooltip, - child: const Icon(Icons.add), + ], ), + floatingActionButton: FloatingActionButton( + onPressed: _createCollection, + tooltip: AppLocalizations.of(context)!.createSequence_tooltip, + child: const Icon(Icons.add), ), + ), ); } } @@ -121,14 +122,14 @@ class LoaderIndicatorView extends StatelessWidget { @override Widget build(BuildContext context) { return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: Loader( - message: Text(AppLocalizations.of(context)!.loading), - ), - ) - ] + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Loader( + message: Text(AppLocalizations.of(context)!.loading), + ), + ), + ], ); } } @@ -146,20 +147,16 @@ class NoElementView extends StatelessWidget { Center( child: Text( AppLocalizations.of(context)!.emptyError, - style: GoogleFonts.nunito( - fontSize: 18, - color: Colors.grey, - fontWeight: FontWeight.w400 - ) - ) + style: GoogleFonts.nunito(fontSize: 18, color: Colors.grey, fontWeight: FontWeight.w400), + ), ) - ] + ], ); } } -class UnkownErrorView extends StatelessWidget { - const UnkownErrorView({ +class UnknownErrorView extends StatelessWidget { + const UnknownErrorView({ super.key, }); @@ -171,14 +168,10 @@ class UnkownErrorView extends StatelessWidget { Center( child: Text( AppLocalizations.of(context)!.unknownError, - style: GoogleFonts.nunito( - fontSize: 20, - color: Colors.red, - fontWeight: FontWeight.w400 - ) - ) + style: GoogleFonts.nunito(fontSize: 20, color: Colors.red, fontWeight: FontWeight.w400), + ), ) - ] + ], ); } -} \ No newline at end of file +} diff --git a/lib/service/api/model/geo_visio.dart b/lib/service/api/model/geo_visio.dart index 6743821..5637e31 100644 --- a/lib/service/api/model/geo_visio.dart +++ b/lib/service/api/model/geo_visio.dart @@ -71,10 +71,7 @@ class GeoVisioCollection { GeoVisioCollection(); String? getThumbUrl() { - var selfCollectionLink = this.links.firstWhere((link) => link.rel == "self"); - if(selfCollectionLink == null) { - return null; - } + var selfCollectionLink = links.firstWhere((link) => link.rel == "self"); return '${selfCollectionLink.href}/thumb.jpg'; } }