mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-22 07:20:39 +00:00
unified SliverList
This commit is contained in:
parent
0055b5f628
commit
7656f55662
3 changed files with 106 additions and 80 deletions
|
@ -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<EquipmentProfilesScreen> {
|
||||
static const maxProfiles = 5; // replace with a constant from iap
|
||||
static const maxProfiles = 5 + 1; // replace with a constant from iap
|
||||
|
||||
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
||||
int get profilesCount => EquipmentProfiles.of(context).length;
|
||||
|
@ -30,45 +31,43 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
elevation: 0,
|
||||
title: Text(S.of(context).equipmentProfiles),
|
||||
return SliverScreen(
|
||||
title: S.of(context).equipmentProfiles,
|
||||
appBarActions: [
|
||||
if (profilesCount < maxProfiles)
|
||||
IconButton(
|
||||
onPressed: _addProfile,
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
body: SafeArea(
|
||||
bottom: false,
|
||||
child: ListView.separated(
|
||||
IconButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
slivers: [
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) => index > 0
|
||||
? Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
Dimens.paddingM,
|
||||
index == 0 ? Dimens.paddingM : 0,
|
||||
Dimens.paddingM,
|
||||
Dimens.paddingM,
|
||||
Dimens.paddingM +
|
||||
MediaQuery.of(context).padding.bottom +
|
||||
Dimens.grid56 +
|
||||
kFloatingActionButtonMargin,
|
||||
),
|
||||
separatorBuilder: (context, index) =>
|
||||
index > 0 ? const SizedBox(height: Dimens.grid16) : const SizedBox.shrink(),
|
||||
itemCount: profilesCount,
|
||||
itemBuilder: (context, index) => index > 0
|
||||
? EquipmentProfileContainer(
|
||||
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,
|
||||
),
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton: profilesCount < maxProfiles
|
||||
? FloatingActionButton(
|
||||
onPressed: _addProfile,
|
||||
child: const Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,34 +12,15 @@ class SettingsScreen extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
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: [
|
||||
return SliverScreen(
|
||||
title: S.of(context).settings,
|
||||
appBarActions: [
|
||||
IconButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
slivers: [
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
<Widget>[
|
||||
|
@ -52,8 +33,6 @@ class SettingsScreen extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
48
lib/screens/shared/sliver_screen/screen_sliver.dart
Normal file
48
lib/screens/shared/sliver_screen/screen_sliver.dart
Normal file
|
@ -0,0 +1,48 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
|
||||
class SliverScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final List<Widget> appBarActions;
|
||||
final List<Widget> 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: <Widget>[
|
||||
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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue