feat(ui): Implement setting the volumes owned

This commit is contained in:
PapaTutuWawa 2023-02-06 16:01:33 +01:00
parent 64bc2821f9
commit e6c1e5e7fe

View File

@ -7,19 +7,38 @@ import 'package:anitrack/src/ui/widgets/dropdown.dart';
import 'package:anitrack/src/ui/widgets/image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
class DetailsPage extends StatelessWidget {
const DetailsPage({
class DetailsPage extends StatefulWidget {
DetailsPage({
super.key,
});
static MaterialPageRoute<dynamic> get route => MaterialPageRoute<dynamic>(
builder: (_) => const DetailsPage(),
builder: (_) => DetailsPage(),
settings: const RouteSettings(
name: detailsRoute,
),
);
@override
DetailsPageState createState() => DetailsPageState();
}
class DetailsPageState extends State<DetailsPage> {
final TextEditingController _volumesOwnedController = TextEditingController();
@override
void initState() {
super.initState();
final state = GetIt.I.get<DetailsBloc>().state;
if (state.trackingType == TrackingMediumType.manga) {
_volumesOwnedController.text = '${(state.data as MangaTrackingData).volumesOwned}';
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -67,7 +86,11 @@ class DetailsPage extends StatelessWidget {
],
),
DropdownSelector<MediumTrackingState>(
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
),
child: DropdownSelector<MediumTrackingState>(
title: state.trackingType == TrackingMediumType.anime ?
'Watch state' :
'Read state',
@ -112,6 +135,82 @@ class DetailsPage extends StatelessWidget {
(state.data as AnimeTrackingData).state :
(state.data as MangaTrackingData).state,
),
),
if (state.trackingType == TrackingMediumType.manga)
Padding(
padding: const EdgeInsets.symmetric(
vertical: 8,
),
child: Row(
children: [
ElevatedButton(
onPressed: () {
final data = (state.data as MangaTrackingData);
if (data.volumesOwned == 0) return;
_volumesOwnedController.text = '${data.volumesOwned - 1}';
context.read<DetailsBloc>().add(
DetailsUpdatedEvent(
data.copyWith(
volumesOwned: data.volumesOwned - 1,
),
),
);
},
child: Icon(Icons.remove),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Volumes owned',
),
keyboardType: TextInputType.numberWithOptions(
signed: false,
decimal: false,
),
textInputAction: TextInputAction.done,
controller: _volumesOwnedController,
onSubmitted: (value) {
final amount = int.parse(value);
if (amount < 0) return;
context.read<DetailsBloc>().add(
DetailsUpdatedEvent(
(state.data as MangaTrackingData).copyWith(
volumesOwned: amount,
),
),
);
},
),
),
),
ElevatedButton(
onPressed: () {
final data = (state.data as MangaTrackingData);
_volumesOwnedController.text = '${data.volumesOwned + 1}';
context.read<DetailsBloc>().add(
DetailsUpdatedEvent(
data.copyWith(
volumesOwned: data.volumesOwned + 1,
),
),
);
},
child: Icon(Icons.add),
),
],
),
),
],
),
);