2024-10-07 13:08:27 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lightmeter/generated/l10n.dart';
|
2024-10-24 10:39:50 +00:00
|
|
|
import 'package:lightmeter/navigation/routes.dart';
|
2024-10-21 09:40:11 +00:00
|
|
|
import 'package:lightmeter/providers/films_provider.dart';
|
2024-10-24 10:09:27 +00:00
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
2024-10-24 10:33:37 +00:00
|
|
|
import 'package:lightmeter/screens/film_edit/flow_film_edit.dart';
|
2024-10-26 10:55:55 +00:00
|
|
|
import 'package:lightmeter/screens/shared/sliver_placeholder/widget_sliver_placeholder.dart';
|
2024-10-07 13:08:27 +00:00
|
|
|
import 'package:lightmeter/screens/shared/sliver_screen/screen_sliver.dart';
|
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
|
|
|
|
|
|
|
class FilmsScreen extends StatefulWidget {
|
|
|
|
const FilmsScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<FilmsScreen> createState() => _FilmsScreenState();
|
|
|
|
}
|
|
|
|
|
2024-10-24 10:09:27 +00:00
|
|
|
class _FilmsScreenState extends State<FilmsScreen> with SingleTickerProviderStateMixin {
|
|
|
|
late final tabController = TabController(length: 2, vsync: this);
|
|
|
|
|
2024-10-26 10:55:55 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
tabController.addListener(() {
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-24 10:33:37 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
tabController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2024-10-07 13:08:27 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SliverScreen(
|
2024-10-24 10:09:27 +00:00
|
|
|
title: Text(S.of(context).films),
|
|
|
|
bottom: TabBar(
|
|
|
|
controller: tabController,
|
|
|
|
tabs: [
|
|
|
|
Tab(text: S.of(context).filmsInUse),
|
|
|
|
Tab(text: S.of(context).filmsCustom),
|
|
|
|
],
|
|
|
|
),
|
2024-10-07 13:08:27 +00:00
|
|
|
appBarActions: [
|
2024-10-24 10:33:37 +00:00
|
|
|
AnimatedBuilder(
|
|
|
|
animation: tabController,
|
|
|
|
builder: (context, _) => AnimatedSwitcher(
|
|
|
|
duration: Dimens.switchDuration,
|
|
|
|
child: tabController.index == 0
|
|
|
|
? const SizedBox.shrink()
|
|
|
|
: IconButton(
|
|
|
|
onPressed: _addFilm,
|
|
|
|
icon: const Icon(Icons.add_outlined),
|
|
|
|
tooltip: S.of(context).tooltipAdd,
|
|
|
|
),
|
|
|
|
),
|
2024-10-07 13:08:27 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
slivers: [
|
2024-10-26 10:55:55 +00:00
|
|
|
if (tabController.index == 0)
|
|
|
|
_FilmsListBuilder(
|
|
|
|
films: Films.predefinedFilmsOf(context).toList(),
|
|
|
|
onFilmSelected: FilmsProvider.of(context).toggleFilm,
|
|
|
|
)
|
|
|
|
else if (tabController.index == 1 && Films.customFilmsOf(context).isNotEmpty)
|
|
|
|
_FilmsListBuilder<FilmExponential>(
|
|
|
|
films: Films.customFilmsOf(context).toList(),
|
|
|
|
onFilmSelected: FilmsProvider.of(context).toggleFilm,
|
|
|
|
onFilmEdit: _editFilm,
|
|
|
|
)
|
|
|
|
else
|
|
|
|
SliverPlaceholder(onTap: _addFilm),
|
2024-10-07 13:08:27 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2024-10-21 09:40:11 +00:00
|
|
|
|
2024-10-24 10:33:37 +00:00
|
|
|
void _addFilm() {
|
|
|
|
Navigator.of(context).pushNamed(
|
2024-10-25 11:01:37 +00:00
|
|
|
NavigationRoutes.filmAddScreen.name,
|
|
|
|
arguments: const FilmEditArgs(),
|
2024-10-24 10:33:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _editFilm(FilmExponential film) {
|
|
|
|
Navigator.of(context).pushNamed(
|
2024-10-24 10:39:50 +00:00
|
|
|
NavigationRoutes.filmEditScreen.name,
|
2024-10-24 10:33:37 +00:00
|
|
|
arguments: FilmEditArgs(film: film),
|
|
|
|
);
|
|
|
|
}
|
2024-10-24 10:09:27 +00:00
|
|
|
}
|
|
|
|
|
2024-10-24 10:33:37 +00:00
|
|
|
class _FilmsListBuilder<T extends Film> extends StatelessWidget {
|
|
|
|
final List<T> films;
|
|
|
|
final void Function(T film, bool value) onFilmSelected;
|
|
|
|
final void Function(T film)? onFilmEdit;
|
2024-10-24 10:09:27 +00:00
|
|
|
|
|
|
|
const _FilmsListBuilder({
|
|
|
|
required this.films,
|
|
|
|
required this.onFilmSelected,
|
|
|
|
this.onFilmEdit,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-10-26 10:55:55 +00:00
|
|
|
return SliverList.builder(
|
2024-10-24 10:09:27 +00:00
|
|
|
itemCount: films.length,
|
2024-10-26 10:55:55 +00:00
|
|
|
itemBuilder: (_, index) => Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
Dimens.paddingM,
|
|
|
|
index == 0 ? Dimens.paddingM : 0,
|
|
|
|
Dimens.paddingM,
|
|
|
|
index == films.length - 1 ? Dimens.paddingM + MediaQuery.paddingOf(context).bottom : 0.0,
|
2024-10-24 10:09:27 +00:00
|
|
|
),
|
2024-10-26 10:55:55 +00:00
|
|
|
child: Card(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
top: index == 0 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero,
|
|
|
|
bottom: index == films.length - 1 ? const Radius.circular(Dimens.borderRadiusL) : Radius.zero,
|
|
|
|
),
|
2024-10-24 10:09:27 +00:00
|
|
|
),
|
2024-10-26 10:55:55 +00:00
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: index == 0 ? Dimens.paddingM : 0.0,
|
|
|
|
bottom: index == films.length - 1 ? Dimens.paddingM : 0.0,
|
|
|
|
),
|
|
|
|
child: CheckboxListTile(
|
|
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
|
|
value: Films.inUseOf(context).contains(films[index]),
|
|
|
|
title: Text(films[index].name),
|
|
|
|
onChanged: (value) {
|
|
|
|
onFilmSelected(films[index], value ?? false);
|
|
|
|
},
|
|
|
|
secondary: onFilmEdit != null
|
|
|
|
? IconButton(
|
|
|
|
onPressed: () => onFilmEdit!(films[index]),
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
2024-10-24 10:09:27 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2024-10-21 09:40:11 +00:00
|
|
|
}
|
2024-10-07 13:08:27 +00:00
|
|
|
}
|