From 16a88f630d3d50b194d6f421e17d479f86974b3e Mon Sep 17 00:00:00 2001 From: sonle Date: Wed, 13 Apr 2022 13:11:59 +0700 Subject: [PATCH] fix: add semantics to widget --- lib/screens/common_widgets/app_bar.dart | 81 +++--- lib/screens/common_widgets/common_button.dart | 7 +- lib/screens/common_widgets/custom_button.dart | 7 +- .../widgets/received_file_list_tile.dart | 16 +- lib/screens/home/home.dart | 17 +- .../widgets/select_contact_widget.dart | 48 ++-- .../widgets/select_file_widget.dart | 230 +++++++++--------- .../widgets/welcome_sceen_home.dart | 1 + 8 files changed, 209 insertions(+), 198 deletions(-) diff --git a/lib/screens/common_widgets/app_bar.dart b/lib/screens/common_widgets/app_bar.dart index 1a98802d..a2cc9b93 100644 --- a/lib/screens/common_widgets/app_bar.dart +++ b/lib/screens/common_widgets/app_bar.dart @@ -208,44 +208,51 @@ class _CustomAppBarState extends State { } Widget menuBar(BuildContext context) { - return GestureDetector( - onTap: () { - Scaffold.of(context).openEndDrawer(); - }, - child: Stack( - alignment: Alignment.topRight, - clipBehavior: Clip.none, - children: [ - Container( - margin: EdgeInsets.only(top: 10.toHeight), - height: 22.toHeight, - width: 22.toWidth, - child: Image.asset( - ImageConstants.drawerIcon, - ), - ), - Consumer( - builder: (context, _fileDownloadChecker, _) { - return _fileDownloadChecker.undownloadedFilesExist - ? Positioned( - right: -4, - top: 2, - child: Container( - decoration: BoxDecoration( - color: Colors.white, - shape: BoxShape.circle, - ), - padding: EdgeInsets.all(1.toHeight), - child: CircleAvatar( - backgroundColor: Colors.red, - radius: 5.toWidth, + return Consumer( + builder: (context, _fileDownloadChecker, _) { + return IconButton( + onPressed: () { + Scaffold.of(context).openEndDrawer(); + }, + alignment: Alignment.topCenter, + tooltip: _fileDownloadChecker.undownloadedFilesExist + ? 'Hamburger Menu & Dot' + : 'Hamburger Menu', + padding: EdgeInsets.zero, + icon: Stack( + alignment: Alignment.topRight, + clipBehavior: Clip.none, + children: [ + Container( + margin: EdgeInsets.only(top: 10.toHeight), + height: 22.toHeight, + width: 22.toWidth, + child: Image.asset( + ImageConstants.drawerIcon, + semanticLabel: '', + ), + ), + _fileDownloadChecker.undownloadedFilesExist + ? Positioned( + right: -4, + top: 2, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + ), + padding: EdgeInsets.all(1.toHeight), + child: CircleAvatar( + backgroundColor: Colors.red, + radius: 5.toWidth, + ), ), - ), - ) - : SizedBox(); - }), - ], - ), + ) + : SizedBox(), + ], + ), + ); + }, ); } } diff --git a/lib/screens/common_widgets/common_button.dart b/lib/screens/common_widgets/common_button.dart index 658ac083..5f9ba265 100644 --- a/lib/screens/common_widgets/common_button.dart +++ b/lib/screens/common_widgets/common_button.dart @@ -25,8 +25,11 @@ class CommonButton extends StatelessWidget { @override Widget build(BuildContext context) { double deviceTextFactor = MediaQuery.of(context).textScaleFactor; - return InkWell( - onTap: onTap, + return TextButton( + onPressed: onTap, + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + ), child: Container( width: width ?? 120.toWidth, height: height ?? 45.toHeight * deviceTextFactor, diff --git a/lib/screens/common_widgets/custom_button.dart b/lib/screens/common_widgets/custom_button.dart index 35022717..6c5c93fd 100644 --- a/lib/screens/common_widgets/custom_button.dart +++ b/lib/screens/common_widgets/custom_button.dart @@ -25,8 +25,11 @@ class CustomButton extends StatelessWidget { : super(key: key); @override Widget build(BuildContext context) { - return GestureDetector( - onTap: onPressed, + return TextButton( + onPressed: onPressed, + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + ), child: Container( width: width ?? 158.toWidth, height: height ?? (50.toHeight), diff --git a/lib/screens/history/widgets/received_file_list_tile.dart b/lib/screens/history/widgets/received_file_list_tile.dart index 56f8fb95..ff1b153a 100644 --- a/lib/screens/history/widgets/received_file_list_tile.dart +++ b/lib/screens/history/widgets/received_file_list_tile.dart @@ -379,8 +379,12 @@ class _ReceivedFilesListTileState extends State { height: 3.toHeight, ), (!isOpen!) - ? GestureDetector( - onTap: () { + ? TextButton( + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + onPressed: () { if (mounted) { setState(() { isOpen = !isOpen; @@ -593,8 +597,12 @@ class _ReceivedFilesListTileState extends State { ); }), ), - GestureDetector( - onTap: () { + TextButton( + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + onPressed: () { if (mounted) { setState(() { isOpen = !isOpen!; diff --git a/lib/screens/home/home.dart b/lib/screens/home/home.dart index 1c9701d4..01711a39 100644 --- a/lib/screens/home/home.dart +++ b/lib/screens/home/home.dart @@ -229,6 +229,8 @@ class _HomeState extends State { children: [ Text( TextStrings().homeDescriptionMobile, + semanticsLabel: + '${TextStrings().appName} \n ${TextStrings().homeDescriptionMobile}', style: GoogleFonts.playfairDisplay( textStyle: TextStyle( fontSize: 38.toFont, @@ -266,18 +268,15 @@ class _HomeState extends State { await _backendService .checkToOnboard(); }), - SizedBox(height: 15.toHeight), - InkWell( - onTap: () { + // SizedBox(height: 15.toHeight), + CustomButton( + onPressed: () { CommonUtilityFunctions() .showResetAtsignDialog(); }, - child: Text( - TextStrings.resetButton, - style: TextStyle( - fontSize: 15.toFont, - fontWeight: FontWeight.bold), - ), + isInverted: true, + width: SizeConfig().screenWidth * 0.8, + buttonText: TextStrings.resetButton, ), ], ), diff --git a/lib/screens/welcome_screen/widgets/select_contact_widget.dart b/lib/screens/welcome_screen/widgets/select_contact_widget.dart index b70b9479..954c4794 100644 --- a/lib/screens/welcome_screen/widgets/select_contact_widget.dart +++ b/lib/screens/welcome_screen/widgets/select_contact_widget.dart @@ -35,7 +35,6 @@ class _SelectContactWidgetState extends State { textTheme: TextTheme( subtitle1: TextStyle( color: ColorConstants.inputFieldColor, - fontWeight: FontWeight.normal, ), ), ), @@ -62,36 +61,31 @@ class _ExpansionTileWidget extends StatelessWidget { _ExpansionTileWidget(this.headerText, this.onSelected); @override Widget build(BuildContext context) { - return ExpansionTile( - tilePadding: SizeConfig().isTablet(context) - ? EdgeInsets.symmetric(vertical: 10.toFont, horizontal: 10.toFont) - : EdgeInsets.only(left: 10.toFont, right: 10.toFont), - backgroundColor: ColorConstants.inputFieldColor, - title: InkWell( - onTap: () { - selectContact(context); - }, - child: Text( - headerText!, - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), + return ListTile( + // tilePadding: SizeConfig().isTablet(context) + // ? EdgeInsets.symmetric(vertical: 10.toFont, horizontal: 10.toFont) + // : EdgeInsets.only(left: 10.toFont, right: 10.toFont), + // backgroundColor: ColorConstants.inputFieldColor, + title: Text( + headerText!, + style: TextStyle( + color: ColorConstants.fadedText, + fontSize: 14.toFont, + fontWeight: FontWeight.normal, ), + semanticsLabel: 'Select @sign from contacts button', ), - trailing: InkWell( - onTap: () { - selectContact(context); - }, - child: Container( - padding: EdgeInsets.symmetric(vertical: 15), - child: Image.asset( - ImageConstants.contactsIcon, - color: Colors.black, - ), + trailing: Container( + padding: EdgeInsets.symmetric(vertical: 15), + child: Image.asset( + ImageConstants.contactsIcon, + color: Colors.black, + semanticLabel: '', ), ), + onTap: () { + selectContact(context); + }, ); } diff --git a/lib/screens/welcome_screen/widgets/select_file_widget.dart b/lib/screens/welcome_screen/widgets/select_file_widget.dart index 31cd4430..35e7f927 100644 --- a/lib/screens/welcome_screen/widgets/select_file_widget.dart +++ b/lib/screens/welcome_screen/widgets/select_file_widget.dart @@ -119,133 +119,129 @@ class _SelectFileWidgetState extends State { @override Widget build(BuildContext context) { return ClipRRect( - child: InkWell( - onTap: () { - _showFileChoice(); - }, - child: Container( - padding: SizeConfig().isTablet(context) - ? EdgeInsets.symmetric(vertical: 10.toFont, horizontal: 10.toFont) - : EdgeInsets.only(left: 10.toFont, right: 10.toFont), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.toFont), - color: ColorConstants.inputFieldColor, - ), - child: Column( - children: [ - ListTile( - contentPadding: EdgeInsets.all(0), - title: Text( - filePickerProvider!.selectedFiles.isEmpty - ? TextStrings().welcomeFilePlaceholder - : TextStrings().welcomeAddFilePlaceholder, - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - )), - subtitle: filePickerProvider!.selectedFiles.isEmpty - ? null - : Text( - double.parse( - filePickerProvider!.totalSize.toString()) <= - 1024 - ? '${filePickerProvider!.totalSize} Kb . ${filePickerProvider!.selectedFiles.length} file(s)' - : '${(filePickerProvider!.totalSize / (1024 * 1024)).toStringAsFixed(2)} Mb . ${filePickerProvider!.selectedFiles.length} file(s)', - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 10.toFont, - fontWeight: FontWeight.normal, - ), + child: Container( + // padding: SizeConfig().isTablet(context) + // ? EdgeInsets.symmetric(vertical: 10.toFont, horizontal: 10.toFont) + // : EdgeInsets.only(left: 10.toFont, right: 10.toFont), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.toFont), + color: ColorConstants.inputFieldColor, + ), + child: Column( + children: [ + ListTile( + // contentPadding: EdgeInsets.all(0), + title: Text( + filePickerProvider!.selectedFiles.isEmpty + ? TextStrings().welcomeFilePlaceholder + : TextStrings().welcomeAddFilePlaceholder, + semanticsLabel: 'Select file to transfer button', + style: TextStyle( + color: ColorConstants.fadedText, + fontSize: 14.toFont, + fontWeight: FontWeight.normal, + )), + subtitle: filePickerProvider!.selectedFiles.isEmpty + ? null + : Text( + double.parse( + filePickerProvider!.totalSize.toString()) <= + 1024 + ? '${filePickerProvider!.totalSize} Kb . ${filePickerProvider!.selectedFiles.length} file(s)' + : '${(filePickerProvider!.totalSize / (1024 * 1024)).toStringAsFixed(2)} Mb . ${filePickerProvider!.selectedFiles.length} file(s)', + style: TextStyle( + color: ColorConstants.fadedText, + fontSize: 10.toFont, + fontWeight: FontWeight.normal, ), - trailing: InkWell( - onTap: () { - _showFileChoice(); - }, - child: Container( - padding: EdgeInsets.symmetric(vertical: 15.toHeight), - child: Icon( - Icons.add_circle, - color: Colors.black, ), - ), + onTap: () { + _showFileChoice(); + }, + trailing: Container( + padding: EdgeInsets.symmetric(vertical: 15.toHeight), + child: Icon( + Icons.add_circle, + color: Colors.black, ), ), - filePickerProvider!.selectedFiles.isNotEmpty - ? ListView.builder( - shrinkWrap: true, - physics: ClampingScrollPhysics(), - itemCount: filePickerProvider!.selectedFiles.isNotEmpty - ? int.parse(filePickerProvider!.selectedFiles.length - .toString()) - : 0, - itemBuilder: (c, index) { - return Consumer( - builder: (context, provider, _) { - if (provider.selectedFiles.isEmpty) { - return SizedBox(); - } - return Container( - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: ColorConstants.dividerColor - .withOpacity(0.1), - width: 1.toHeight, - ), + ), + filePickerProvider!.selectedFiles.isNotEmpty + ? ListView.builder( + shrinkWrap: true, + physics: ClampingScrollPhysics(), + itemCount: filePickerProvider!.selectedFiles.isNotEmpty + ? int.parse(filePickerProvider!.selectedFiles.length + .toString()) + : 0, + itemBuilder: (c, index) { + return Consumer( + builder: (context, provider, _) { + if (provider.selectedFiles.isEmpty) { + return SizedBox(); + } + return Container( + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: ColorConstants.dividerColor + .withOpacity(0.1), + width: 1.toHeight, ), ), - child: ListTile( - title: Text( - provider.selectedFiles[index].name.toString(), - style: TextStyle( - color: Colors.black, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), + ), + child: ListTile( + title: Text( + provider.selectedFiles[index].name.toString(), + style: TextStyle( + color: Colors.black, + fontSize: 14.toFont, + fontWeight: FontWeight.normal, ), - subtitle: Text( - double.parse(provider.selectedFiles[index].size - .toString()) <= - 1024 - ? '${provider.selectedFiles[index].size} Kb' + - ' . ${provider.selectedFiles[index].extension}' - : '${(provider.selectedFiles[index].size / (1024 * 1024)).toStringAsFixed(2)} Mb' + - ' . ${provider.selectedFiles[index].extension}', - style: TextStyle( - color: ColorConstants.fadedText, - fontSize: 14.toFont, - fontWeight: FontWeight.normal, - ), + ), + subtitle: Text( + double.parse(provider.selectedFiles[index].size + .toString()) <= + 1024 + ? '${provider.selectedFiles[index].size} Kb' + + ' . ${provider.selectedFiles[index].extension}' + : '${(provider.selectedFiles[index].size / (1024 * 1024)).toStringAsFixed(2)} Mb' + + ' . ${provider.selectedFiles[index].extension}', + style: TextStyle( + color: ColorConstants.fadedText, + fontSize: 14.toFont, + fontWeight: FontWeight.normal, ), - leading: CommonUtilityFunctions().thumbnail( - provider.selectedFiles[index].extension - .toString(), - provider.selectedFiles[index].path - .toString()), - trailing: IconButton( - icon: Icon(Icons.clear), - onPressed: () { - setState(() { - provider.selectedFiles.removeAt(index); - provider.calculateSize(); - provider.hasSelectedFilesChanged = true; - }); - if (provider.selectedFiles.isEmpty) { - widget.onUpdate(false); - } else { - widget.onUpdate(true); - } - }, + ), + leading: CommonUtilityFunctions().thumbnail( + provider.selectedFiles[index].extension + .toString(), + provider.selectedFiles[index].path + .toString()), + trailing: IconButton( + icon: Icon( + Icons.clear, ), + onPressed: () { + setState(() { + provider.selectedFiles.removeAt(index); + provider.calculateSize(); + provider.hasSelectedFilesChanged = true; + }); + if (provider.selectedFiles.isEmpty) { + widget.onUpdate(false); + } else { + widget.onUpdate(true); + } + }, ), - ); - }); - }, - ) - : SizedBox(), - ], - ), + ), + ); + }); + }, + ) + : SizedBox(), + ], ), ), ); diff --git a/lib/screens/welcome_screen/widgets/welcome_sceen_home.dart b/lib/screens/welcome_screen/widgets/welcome_sceen_home.dart index 889993e8..e44e9530 100644 --- a/lib/screens/welcome_screen/widgets/welcome_sceen_home.dart +++ b/lib/screens/welcome_screen/widgets/welcome_sceen_home.dart @@ -75,6 +75,7 @@ class _WelcomeScreenHomeState extends State { children: [ Text( TextStrings().welcome, + semanticsLabel: TextStrings().welcome, style: GoogleFonts.playfairDisplay( textStyle: TextStyle( fontSize: 26.toFont,