From dfafe41aa9f80beab775f9a1fa1f7338417ca5a8 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 29 Sep 2023 19:02:18 +0200 Subject: [PATCH] fix: Fix task / shares overview switcher for iOS --- lib/screens/CreateTaskScreen.dart | 474 +++++++++++++------------- lib/screens/SharesOverviewScreen.dart | 171 ++++------ 2 files changed, 299 insertions(+), 346 deletions(-) diff --git a/lib/screens/CreateTaskScreen.dart b/lib/screens/CreateTaskScreen.dart index 2397a746..e2eee72e 100644 --- a/lib/screens/CreateTaskScreen.dart +++ b/lib/screens/CreateTaskScreen.dart @@ -9,6 +9,7 @@ import 'package:flutter_platform_widgets/flutter_platform_widgets.dart' hide PlatformListTile; import 'package:locus/constants/spacing.dart'; import 'package:locus/screens/create_task_screen_widgets/ExampleTasksRoulette.dart'; +import 'package:locus/services/settings_service/index.dart'; import 'package:locus/services/task_service/index.dart'; import 'package:locus/utils/theme.dart'; import 'package:locus/widgets/MIUISelectField.dart'; @@ -21,7 +22,6 @@ import 'package:provider/provider.dart'; import '../models/log.dart'; import '../services/log_service.dart'; -import 'package:locus/services/settings_service/index.dart'; import '../widgets/PlatformListTile.dart'; import '../widgets/WarningText.dart'; @@ -237,269 +237,255 @@ class _CreateTaskScreenState extends State final l10n = AppLocalizations.of(context); final settings = context.read(); - return PlatformScaffold( - appBar: PlatformAppBar( - title: Text(l10n.sharesOverviewScreen_createTask), - material: (_, __) => MaterialAppBarData( - centerTitle: true, - ), - ), - material: (_, __) => MaterialScaffoldData( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - ), - body: SafeArea( - child: Padding( - padding: const EdgeInsets.all(MEDIUM_SPACE), - child: Center( - child: Form( - key: _formKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - SingleChildScrollView( - child: Column( - children: [ - Column( - children: [ - const SizedBox(height: SMALL_SPACE), - Text( - l10n.createTask_title, - style: getSubTitleTextStyle(context), - ), - ], - ), - const SizedBox(height: LARGE_SPACE), - Column( - children: [ - Focus( - onFocusChange: (hasFocus) { - if (!hasFocus) { - return; + return SafeArea( + child: Padding( + padding: const EdgeInsets.all(MEDIUM_SPACE), + child: Center( + child: Form( + key: _formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + SingleChildScrollView( + child: Column( + children: [ + Column( + children: [ + const SizedBox(height: SMALL_SPACE), + Text( + l10n.createTask_title, + style: getSubTitleTextStyle(context), + ), + ], + ), + const SizedBox(height: LARGE_SPACE), + Column( + children: [ + Focus( + onFocusChange: (hasFocus) { + if (!hasFocus) { + return; + } + + setState(() { + showExamples = true; + }); + }, + child: PlatformTextFormField( + controller: _nameController, + textInputAction: TextInputAction.next, + validator: (value) { + if (value == null || value.isEmpty) { + return l10n.fields_errors_isEmpty; + } + + if (!StringUtils.isAscii(value)) { + return l10n.fields_errors_invalidCharacters; } - setState(() { - showExamples = true; - }); + return null; }, - child: PlatformTextFormField( - controller: _nameController, - textInputAction: TextInputAction.next, - validator: (value) { - if (value == null || value.isEmpty) { - return l10n.fields_errors_isEmpty; - } - - if (!StringUtils.isAscii(value)) { - return l10n.fields_errors_invalidCharacters; - } - - return null; - }, - keyboardType: TextInputType.name, - autofillHints: const [AutofillHints.name], - material: (_, __) => MaterialTextFormFieldData( - decoration: InputDecoration( - labelText: - l10n.createTask_fields_name_label, - prefixIcon: Icon(context.platformIcons.tag), - ), + keyboardType: TextInputType.name, + autofillHints: const [AutofillHints.name], + material: (_, __) => MaterialTextFormFieldData( + decoration: InputDecoration( + labelText: l10n.createTask_fields_name_label, + prefixIcon: Icon(context.platformIcons.tag), ), - cupertino: (_, __) => - CupertinoTextFormFieldData( - placeholder: - l10n.createTask_fields_name_label, - prefix: Icon(context.platformIcons.tag), + ), + cupertino: (_, __) => CupertinoTextFormFieldData( + placeholder: l10n.createTask_fields_name_label, + prefix: Icon(context.platformIcons.tag), + ), + ) + .animate() + .slide( + duration: IN_DURATION, + curve: Curves.easeOut, + begin: const Offset(0, 0.2), + ) + .fadeIn( + delay: IN_DELAY, + duration: IN_DURATION, + curve: Curves.easeOut, ), - ) - .animate() - .slide( - duration: IN_DURATION, - curve: Curves.easeOut, - begin: const Offset(0, 0.2), - ) - .fadeIn( - delay: IN_DELAY, - duration: IN_DURATION, - curve: Curves.easeOut, - ), + ), + if (showExamples) + ExampleTasksRoulette( + onSelected: (example) { + FocusManager.instance.primaryFocus?.unfocus(); + + _nameController.text = example.name; + _timersController + ..clear() + ..addAll(example.timers); + }, ), - if (showExamples) - ExampleTasksRoulette( - onSelected: (example) { - FocusManager.instance.primaryFocus?.unfocus(); - - _nameController.text = example.name; - _timersController - ..clear() - ..addAll(example.timers); - }, + if (anotherTaskAlreadyExists) ...[ + const SizedBox(height: MEDIUM_SPACE), + WarningText( + l10n.createTask_sameTaskNameAlreadyExists, + ), + ], + const SizedBox(height: MEDIUM_SPACE), + if (settings.isMIUI()) ...[ + MIUISelectField( + label: l10n.createTask_fields_relays_label, + actionText: + l10n.createTask_fields_relays_selectLabel( + _relaysController.relays.length, ), - if (anotherTaskAlreadyExists) ...[ - const SizedBox(height: MEDIUM_SPACE), - WarningText( - l10n.createTask_sameTaskNameAlreadyExists, + icon: const Icon(Icons.dns_rounded), + onPressed: showRelaysSheet, + ).animate().then(delay: IN_DELAY * 4).fadeIn( + delay: IN_DELAY, + duration: IN_DURATION, + curve: Curves.easeOut, + ), + MIUISelectField( + label: l10n.createTask_fields_timers_label, + actionText: + l10n.createTask_fields_timers_selectLabel( + _timersController.timers.length, ), - ], - const SizedBox(height: MEDIUM_SPACE), - if (settings.isMIUI()) ...[ - MIUISelectField( - label: l10n.createTask_fields_relays_label, - actionText: - l10n.createTask_fields_relays_selectLabel( - _relaysController.relays.length, + icon: const Icon(Icons.timer_rounded), + onPressed: showTimersSheet, + ).animate().then(delay: IN_DELAY * 4).fadeIn( + delay: IN_DELAY, + duration: IN_DURATION, + curve: Curves.easeOut, ), - icon: const Icon(Icons.dns_rounded), - onPressed: showRelaysSheet, - ).animate().then(delay: IN_DELAY * 4).fadeIn( - delay: IN_DELAY, - duration: IN_DURATION, - curve: Curves.easeOut, + ] else + Wrap( + alignment: WrapAlignment.spaceEvenly, + spacing: SMALL_SPACE, + crossAxisAlignment: WrapCrossAlignment.center, + direction: Axis.horizontal, + children: [ + PlatformElevatedButton( + material: (_, __) => + MaterialElevatedButtonData( + icon: PlatformWidget( + material: (_, __) => + const Icon(Icons.dns_rounded), + cupertino: (_, __) => const Icon( + CupertinoIcons.list_bullet), + ), ), - MIUISelectField( - label: l10n.createTask_fields_timers_label, - actionText: - l10n.createTask_fields_timers_selectLabel( - _timersController.timers.length, - ), - icon: const Icon(Icons.timer_rounded), - onPressed: showTimersSheet, - ).animate().then(delay: IN_DELAY * 4).fadeIn( - delay: IN_DELAY, - duration: IN_DURATION, - curve: Curves.easeOut, + cupertino: (_, __) => + CupertinoElevatedButtonData( + padding: getSmallButtonPadding(context), ), - ] else - Wrap( - alignment: WrapAlignment.spaceEvenly, - spacing: SMALL_SPACE, - crossAxisAlignment: WrapCrossAlignment.center, - direction: Axis.horizontal, - children: [ - PlatformElevatedButton( - material: (_, __) => - MaterialElevatedButtonData( - icon: PlatformWidget( - material: (_, __) => - const Icon(Icons.dns_rounded), - cupertino: (_, __) => const Icon( - CupertinoIcons.list_bullet), - ), - ), - cupertino: (_, __) => - CupertinoElevatedButtonData( - padding: getSmallButtonPadding(context), - ), - onPressed: showRelaysSheet, - child: Text( - l10n.createTask_fields_relays_selectLabel( - _relaysController.relays.length, - ), + onPressed: showRelaysSheet, + child: Text( + l10n.createTask_fields_relays_selectLabel( + _relaysController.relays.length, ), - ) - .animate() - .then(delay: IN_DELAY * 4) - .slide( - duration: IN_DURATION, - curve: Curves.easeOut, - begin: const Offset(0.2, 0), - ) - .fadeIn( - delay: IN_DELAY, - duration: IN_DURATION, - curve: Curves.easeOut, - ), - PlatformElevatedButton( - material: (_, __) => - MaterialElevatedButtonData( - icon: const Icon(Icons.timer_rounded), + ), + ) + .animate() + .then(delay: IN_DELAY * 4) + .slide( + duration: IN_DURATION, + curve: Curves.easeOut, + begin: const Offset(0.2, 0), + ) + .fadeIn( + delay: IN_DELAY, + duration: IN_DURATION, + curve: Curves.easeOut, ), - cupertino: (_, __) => - CupertinoElevatedButtonData( - padding: getSmallButtonPadding(context), + PlatformElevatedButton( + material: (_, __) => + MaterialElevatedButtonData( + icon: const Icon(Icons.timer_rounded), + ), + cupertino: (_, __) => + CupertinoElevatedButtonData( + padding: getSmallButtonPadding(context), + ), + onPressed: showTimersSheet, + child: Text( + l10n.createTask_fields_timers_selectLabel( + _timersController.timers.length, ), - onPressed: showTimersSheet, - child: Text( - l10n.createTask_fields_timers_selectLabel( - _timersController.timers.length, - ), + ), + ) + .animate() + .then(delay: IN_DELAY * 5) + .slide( + duration: IN_DURATION, + curve: Curves.easeOut, + begin: const Offset(-0.2, 0), + ) + .fadeIn( + delay: IN_DELAY, + duration: IN_DURATION, + curve: Curves.easeOut, ), - ) - .animate() - .then(delay: IN_DELAY * 5) - .slide( - duration: IN_DURATION, - curve: Curves.easeOut, - begin: const Offset(-0.2, 0), - ) - .fadeIn( - delay: IN_DELAY, - duration: IN_DURATION, - curve: Curves.easeOut, - ), - ], - ), - const SizedBox(height: MEDIUM_SPACE), - getScheduleNowWidget(), - ], - ), - ], + ], + ), + const SizedBox(height: MEDIUM_SPACE), + getScheduleNowWidget(), + ], + ), + ], + ), + ), + if (errorMessage != null) ...[ + Text( + errorMessage!, + textAlign: TextAlign.center, + style: getBodyTextTextStyle(context).copyWith( + color: getErrorColor(context), ), ), - if (errorMessage != null) ...[ - Text( - errorMessage!, - textAlign: TextAlign.center, - style: getBodyTextTextStyle(context).copyWith( - color: getErrorColor(context), - ), + const SizedBox(height: MEDIUM_SPACE), + ], + if (_isError) ...[ + Text( + l10n.unknownError, + style: getBodyTextTextStyle(context).copyWith( + color: getErrorColor(context), ), - const SizedBox(height: MEDIUM_SPACE), - ], - if (_isError) ...[ - Text( - l10n.unknownError, - style: getBodyTextTextStyle(context).copyWith( - color: getErrorColor(context), - ), + ), + ], + PlatformElevatedButton( + padding: const EdgeInsets.all(MEDIUM_SPACE), + onPressed: () { + if (!_formKey.currentState!.validate()) { + return; + } + + if (_relaysController.relays.isEmpty) { + setState(() { + errorMessage = l10n.createTask_errors_emptyRelays; + }); + return; + } + + createTask(); + }, + child: Text( + l10n.createTask_createLabel, + style: TextStyle( + fontSize: getActionButtonSize(context), ), - ], - PlatformElevatedButton( - padding: const EdgeInsets.all(MEDIUM_SPACE), - onPressed: () { - if (!_formKey.currentState!.validate()) { - return; - } - - if (_relaysController.relays.isEmpty) { - setState(() { - errorMessage = l10n.createTask_errors_emptyRelays; - }); - return; - } - - createTask(); - }, - child: Text( - l10n.createTask_createLabel, - style: TextStyle( - fontSize: getActionButtonSize(context), - ), + ), + ) + .animate() + .then(delay: IN_DELAY * 8) + .slide( + duration: 500.ms, + curve: Curves.easeOut, + begin: const Offset(0, 1.3), + ) + .fadeIn( + duration: 500.ms, + curve: Curves.easeOut, ), - ) - .animate() - .then(delay: IN_DELAY * 8) - .slide( - duration: 500.ms, - curve: Curves.easeOut, - begin: const Offset(0, 1.3), - ) - .fadeIn( - duration: 500.ms, - curve: Curves.easeOut, - ), - ], - ), + ], ), ), ), diff --git a/lib/screens/SharesOverviewScreen.dart b/lib/screens/SharesOverviewScreen.dart index 9ff2d43f..fa4fb5ac 100644 --- a/lib/screens/SharesOverviewScreen.dart +++ b/lib/screens/SharesOverviewScreen.dart @@ -6,12 +6,12 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:locus/screens/shares_overview_screen_widgets/screens/EmptyScreen.dart'; import 'package:locus/screens/shares_overview_screen_widgets/screens/TasksOverviewScreen.dart'; +import 'package:locus/services/settings_service/index.dart'; import 'package:locus/services/task_service/index.dart'; import 'package:locus/services/view_service/index.dart'; import 'package:locus/utils/theme.dart'; import 'package:provider/provider.dart'; -import 'package:locus/services/settings_service/index.dart'; import 'CreateTaskScreen.dart'; import 'shares_overview_screen_widgets/values.dart'; @@ -26,22 +26,9 @@ class SharesOverviewScreen extends StatefulWidget { class _SharesOverviewScreenState extends State { final listViewKey = GlobalKey(); - final PageController _tabController = PageController(); late final TaskService taskService; int activeTab = 0; - void _changeTab(final int newTab) { - setState(() { - activeTab = newTab; - }); - - _tabController.animateToPage( - newTab, - duration: getTransitionDuration(context), - curve: Curves.easeInOut, - ); - } - PlatformAppBar? getAppBar() { final l10n = AppLocalizations.of(context); @@ -68,103 +55,83 @@ class _SharesOverviewScreenState extends State { } return PlatformScaffold( - material: (_, __) => - MaterialScaffoldData( - floatingActionButton: OpenContainer( - transitionDuration: const Duration(milliseconds: 500), - transitionType: ContainerTransitionType.fadeThrough, - openBuilder: (_, action) => - CreateTaskScreen( - onCreated: () { - Navigator.pop(context); - }, - ), - closedBuilder: (context, action) => - InkWell( - onTap: action, - child: SizedBox( - height: FAB_DIMENSION, - width: FAB_DIMENSION, - child: Center( - child: Icon( - settings.isMIUI() || isCupertino(context) - ? CupertinoIcons.plus - : Icons.add, - color: Theme - .of(context) - .colorScheme - .primary, - size: settings.isMIUI() ? 34 : 38, - ), - ), - ), - ), - closedElevation: 6.0, - closedShape: const RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(30), - ), - ), - openColor: Colors.transparent, - closedColor: getIsDarkMode(context) - ? HSLColor.fromColor(Theme - .of(context) - .colorScheme - .primary) - .withLightness(.15) - .withSaturation(1) - .toColor() - : Theme - .of(context) - .colorScheme - .primary, - ).animate().scale( - duration: 500.ms, delay: 1.seconds, curve: Curves.bounceOut)), - cupertino: (_, __) => - CupertinoPageScaffoldData( - backgroundColor: getIsDarkMode(context) - ? null - : CupertinoColors.tertiarySystemGroupedBackground - .resolveFrom(context), + material: (_, __) => MaterialScaffoldData( + floatingActionButton: OpenContainer( + transitionDuration: const Duration(milliseconds: 500), + transitionType: ContainerTransitionType.fadeThrough, + openBuilder: (_, action) => CreateTaskScreen( + onCreated: () { + Navigator.pop(context); + }, + ), + closedBuilder: (context, action) => InkWell( + onTap: action, + child: SizedBox( + height: FAB_DIMENSION, + width: FAB_DIMENSION, + child: Center( + child: Icon( + settings.isMIUI() || isCupertino(context) + ? CupertinoIcons.plus + : Icons.add, + color: Theme.of(context).colorScheme.primary, + size: settings.isMIUI() ? 34 : 38, + ), + ), ), + ), + closedElevation: 6.0, + closedShape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(30), + ), + ), + openColor: Colors.transparent, + closedColor: getIsDarkMode(context) + ? HSLColor.fromColor(Theme.of(context).colorScheme.primary) + .withLightness(.15) + .withSaturation(1) + .toColor() + : Theme.of(context).colorScheme.primary, + ).animate().scale( + duration: 500.ms, delay: 1.seconds, curve: Curves.bounceOut)), + cupertino: (_, __) => CupertinoPageScaffoldData( + backgroundColor: getIsDarkMode(context) + ? null + : CupertinoColors.tertiarySystemGroupedBackground + .resolveFrom(context), + ), appBar: getAppBar(), // Settings bottomNavBar via cupertino data class does not work bottomNavBar: isCupertino(context) ? PlatformNavBar( - material: (_, __) => - MaterialNavBarData( - backgroundColor: Theme - .of(context) - .dialogBackgroundColor, - elevation: 0, - padding: const EdgeInsets.all(0)), - itemChanged: _changeTab, - currentIndex: activeTab, - items: [ - BottomNavigationBarItem( - icon: const Icon(CupertinoIcons.list_bullet), - label: l10n.sharesOverviewScreen_tasks, - ), - BottomNavigationBarItem( - icon: const Icon(CupertinoIcons.location_fill), - label: l10n.sharesOverviewScreen_createTask, - ), - ], - ) + itemChanged: (index) { + setState(() { + activeTab = index; + }); + }, + currentIndex: activeTab, + items: [ + BottomNavigationBarItem( + icon: const Icon(CupertinoIcons.list_bullet), + label: l10n.sharesOverviewScreen_tasks, + ), + BottomNavigationBarItem( + icon: const Icon(CupertinoIcons.location_fill), + label: l10n.sharesOverviewScreen_createTask, + ), + ], + ) : null, - body: PageView( - controller: _tabController, - physics: const NeverScrollableScrollPhysics(), - children: [ - const TasksOverviewScreen(), - if (isCupertino(context)) - CreateTaskScreen( + body: activeTab == 0 + ? const TasksOverviewScreen() + : CreateTaskScreen( onCreated: () { - _changeTab(0); + setState(() { + activeTab = 0; + }); }, ), - ], - ), ); } }