feat(ui): Implement setting the volumes owned
This commit is contained in:
parent
64bc2821f9
commit
e6c1e5e7fe
@ -7,19 +7,38 @@ import 'package:anitrack/src/ui/widgets/dropdown.dart';
|
|||||||
import 'package:anitrack/src/ui/widgets/image.dart';
|
import 'package:anitrack/src/ui/widgets/image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:get_it/get_it.dart';
|
||||||
|
|
||||||
class DetailsPage extends StatelessWidget {
|
class DetailsPage extends StatefulWidget {
|
||||||
const DetailsPage({
|
DetailsPage({
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
static MaterialPageRoute<dynamic> get route => MaterialPageRoute<dynamic>(
|
static MaterialPageRoute<dynamic> get route => MaterialPageRoute<dynamic>(
|
||||||
builder: (_) => const DetailsPage(),
|
builder: (_) => DetailsPage(),
|
||||||
settings: const RouteSettings(
|
settings: const RouteSettings(
|
||||||
name: detailsRoute,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
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 ?
|
title: state.trackingType == TrackingMediumType.anime ?
|
||||||
'Watch state' :
|
'Watch state' :
|
||||||
'Read state',
|
'Read state',
|
||||||
@ -112,6 +135,82 @@ class DetailsPage extends StatelessWidget {
|
|||||||
(state.data as AnimeTrackingData).state :
|
(state.data as AnimeTrackingData).state :
|
||||||
(state.data as MangaTrackingData).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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user