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/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
import 'package:lightmeter/providers/equipment_profile_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.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 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
import 'components/equipment_profile_container/widget_container_equipment_profile.dart';
|
import 'components/equipment_profile_container/widget_container_equipment_profile.dart';
|
||||||
|
@ -15,7 +16,7 @@ class EquipmentProfilesScreen extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
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 = [];
|
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
|
||||||
int get profilesCount => EquipmentProfiles.of(context).length;
|
int get profilesCount => EquipmentProfiles.of(context).length;
|
||||||
|
@ -30,45 +31,43 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return SliverScreen(
|
||||||
appBar: AppBar(
|
title: S.of(context).equipmentProfiles,
|
||||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
appBarActions: [
|
||||||
elevation: 0,
|
if (profilesCount < maxProfiles)
|
||||||
title: Text(S.of(context).equipmentProfiles),
|
IconButton(
|
||||||
),
|
onPressed: _addProfile,
|
||||||
body: SafeArea(
|
icon: const Icon(Icons.add),
|
||||||
bottom: false,
|
|
||||||
child: ListView.separated(
|
|
||||||
padding: EdgeInsets.fromLTRB(
|
|
||||||
Dimens.paddingM,
|
|
||||||
Dimens.paddingM,
|
|
||||||
Dimens.paddingM,
|
|
||||||
Dimens.paddingM +
|
|
||||||
MediaQuery.of(context).padding.bottom +
|
|
||||||
Dimens.grid56 +
|
|
||||||
kFloatingActionButtonMargin,
|
|
||||||
),
|
),
|
||||||
separatorBuilder: (context, index) =>
|
IconButton(
|
||||||
index > 0 ? const SizedBox(height: Dimens.grid16) : const SizedBox.shrink(),
|
onPressed: Navigator.of(context).pop,
|
||||||
itemCount: profilesCount,
|
icon: const Icon(Icons.close),
|
||||||
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(),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
slivers: [
|
||||||
floatingActionButton: profilesCount < maxProfiles
|
SliverList(
|
||||||
? FloatingActionButton(
|
delegate: SliverChildBuilderDelegate(
|
||||||
onPressed: _addProfile,
|
(context, index) => index > 0
|
||||||
child: const Icon(Icons.add),
|
? Padding(
|
||||||
)
|
padding: EdgeInsets.fromLTRB(
|
||||||
: null,
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/generated/l10n.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/about/widget_settings_section_about.dart';
|
||||||
import 'components/general/widget_settings_section_general.dart';
|
import 'components/general/widget_settings_section_general.dart';
|
||||||
|
@ -12,48 +12,27 @@ class SettingsScreen extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return SliverScreen(
|
||||||
body: SafeArea(
|
title: S.of(context).settings,
|
||||||
top: false,
|
appBarActions: [
|
||||||
bottom: false,
|
IconButton(
|
||||||
child: CustomScrollView(
|
onPressed: Navigator.of(context).pop,
|
||||||
slivers: <Widget>[
|
icon: const Icon(Icons.close),
|
||||||
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(
|
|
||||||
<Widget>[
|
|
||||||
const MeteringSettingsSection(),
|
|
||||||
const GeneralSettingsSection(),
|
|
||||||
const ThemeSettingsSection(),
|
|
||||||
const AboutSettingsSection(),
|
|
||||||
SizedBox(height: MediaQuery.of(context).padding.bottom),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
slivers: [
|
||||||
|
SliverList(
|
||||||
|
delegate: SliverChildListDelegate(
|
||||||
|
<Widget>[
|
||||||
|
const MeteringSettingsSection(),
|
||||||
|
const GeneralSettingsSection(),
|
||||||
|
const ThemeSettingsSection(),
|
||||||
|
const AboutSettingsSection(),
|
||||||
|
SizedBox(height: MediaQuery.of(context).padding.bottom),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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