diff --git a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart index a062f62..af15f4a 100644 --- a/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart +++ b/lib/screens/settings/components/metering/components/equipment_profiles/components/equipment_profile_screen/screen_equipment_profile.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/providers/equipment_profile_provider.dart'; import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'components/equipment_profile_container/widget_container_equipment_profile.dart'; @@ -15,7 +16,7 @@ class EquipmentProfilesScreen extends StatefulWidget { } class _EquipmentProfilesScreenState extends State { - static const maxProfiles = 5; // replace with a constant from iap + static const maxProfiles = 5 + 1; // replace with a constant from iap late List> profileContainersKeys = []; int get profilesCount => EquipmentProfiles.of(context).length; @@ -30,45 +31,43 @@ class _EquipmentProfilesScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - elevation: 0, - title: Text(S.of(context).equipmentProfiles), - ), - body: SafeArea( - bottom: false, - child: ListView.separated( - padding: EdgeInsets.fromLTRB( - Dimens.paddingM, - Dimens.paddingM, - Dimens.paddingM, - Dimens.paddingM + - MediaQuery.of(context).padding.bottom + - Dimens.grid56 + - kFloatingActionButtonMargin, + return SliverScreen( + title: S.of(context).equipmentProfiles, + appBarActions: [ + if (profilesCount < maxProfiles) + IconButton( + onPressed: _addProfile, + icon: const Icon(Icons.add), ), - separatorBuilder: (context, index) => - index > 0 ? const SizedBox(height: Dimens.grid16) : const SizedBox.shrink(), - itemCount: profilesCount, - itemBuilder: (context, index) => index > 0 - ? EquipmentProfileContainer( - key: profileContainersKeys[index], - data: EquipmentProfiles.of(context)[index], - onExpand: () => _keepExpandedAt(index), - onUpdate: (profileData) => _updateProfileAt(profileData, index), - onDelete: () => _removeProfileAt(index), - ) - : const SizedBox.shrink(), + IconButton( + onPressed: Navigator.of(context).pop, + icon: const Icon(Icons.close), ), - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, - floatingActionButton: profilesCount < maxProfiles - ? FloatingActionButton( - onPressed: _addProfile, - child: const Icon(Icons.add), - ) - : null, + ], + slivers: [ + SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) => index > 0 + ? Padding( + padding: EdgeInsets.fromLTRB( + Dimens.paddingM, + index == 0 ? Dimens.paddingM : 0, + Dimens.paddingM, + Dimens.paddingM, + ), + child: EquipmentProfileContainer( + key: profileContainersKeys[index], + data: EquipmentProfiles.of(context)[index], + onExpand: () => _keepExpandedAt(index), + onUpdate: (profileData) => _updateProfileAt(profileData, index), + onDelete: () => _removeProfileAt(index), + ), + ) + : const SizedBox.shrink(), + childCount: profileContainersKeys.length, + ), + ), + ], ); } diff --git a/lib/screens/settings/screen_settings.dart b/lib/screens/settings/screen_settings.dart index 6f225ff..81a569a 100644 --- a/lib/screens/settings/screen_settings.dart +++ b/lib/screens/settings/screen_settings.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; -import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart'; import 'components/about/widget_settings_section_about.dart'; import 'components/general/widget_settings_section_general.dart'; @@ -12,48 +12,27 @@ class SettingsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - body: SafeArea( - top: false, - bottom: false, - child: CustomScrollView( - slivers: [ - SliverAppBar( - pinned: true, - automaticallyImplyLeading: false, - expandedHeight: Dimens.grid168, - flexibleSpace: FlexibleSpaceBar( - centerTitle: false, - titlePadding: const EdgeInsets.all(Dimens.paddingM), - title: Text( - S.of(context).settings, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface, - fontSize: 24, - ), - ), - ), - actions: [ - IconButton( - onPressed: Navigator.of(context).pop, - icon: const Icon(Icons.close), - ), - ], - ), - SliverList( - delegate: SliverChildListDelegate( - [ - const MeteringSettingsSection(), - const GeneralSettingsSection(), - const ThemeSettingsSection(), - const AboutSettingsSection(), - SizedBox(height: MediaQuery.of(context).padding.bottom), - ], - ), - ), - ], + return SliverScreen( + title: S.of(context).settings, + appBarActions: [ + IconButton( + onPressed: Navigator.of(context).pop, + icon: const Icon(Icons.close), ), - ), + ], + slivers: [ + SliverList( + delegate: SliverChildListDelegate( + [ + const MeteringSettingsSection(), + const GeneralSettingsSection(), + const ThemeSettingsSection(), + const AboutSettingsSection(), + SizedBox(height: MediaQuery.of(context).padding.bottom), + ], + ), + ), + ], ); } } diff --git a/lib/screens/shared/sliver_screen/screen_sliver.dart b/lib/screens/shared/sliver_screen/screen_sliver.dart new file mode 100644 index 0000000..d4542b1 --- /dev/null +++ b/lib/screens/shared/sliver_screen/screen_sliver.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:lightmeter/res/dimens.dart'; + +class SliverScreen extends StatelessWidget { + final String title; + final List appBarActions; + final List slivers; + + const SliverScreen({ + required this.title, + required this.appBarActions, + required this.slivers, + super.key, + }); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: SafeArea( + top: false, + bottom: false, + child: CustomScrollView( + slivers: [ + SliverAppBar( + pinned: true, + automaticallyImplyLeading: false, + expandedHeight: Dimens.grid168, + flexibleSpace: FlexibleSpaceBar( + centerTitle: false, + titlePadding: const EdgeInsets.all(Dimens.paddingM), + title: Text( + title, + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface, + fontSize: Dimens.grid24, + ), + ), + ), + actions: appBarActions, + ), + ...slivers, + SliverToBoxAdapter(child: SizedBox(height: MediaQuery.of(context).padding.bottom)), + ], + ), + ), + ); + } +}