diff --git a/lib/widgets/checkbox_with_label.dart b/lib/widgets/checkbox_with_label.dart new file mode 100644 index 0000000..4939249 --- /dev/null +++ b/lib/widgets/checkbox_with_label.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; + +class CheckboxWithLabel extends StatefulWidget { + const CheckboxWithLabel({ + super.key, + required String this.label, + required this.callback, + }); + + final String label; + final Function(bool state) callback; + + @override + State createState() => _CheckboxWithLabelState(); +} + +class _CheckboxWithLabelState extends State { + bool isChecked = false; + + @override + Widget build(BuildContext context) { + Color getColor(Set states) { + const Set interactiveStates = { + WidgetState.pressed, + WidgetState.hovered, + WidgetState.focused, + }; + if (states.any(interactiveStates.contains)) { + return Colors.blue; + } + return Colors.black54; + } + + return Row( + children: [ + Checkbox( + checkColor: Colors.white, + fillColor: WidgetStateProperty.resolveWith(getColor), + side: WidgetStateBorderSide.resolveWith( + (states) => BorderSide(width: 1.0, color: Colors.grey), + ), + value: isChecked, + onChanged: (bool? value) { + setState(() { + isChecked = value!; + widget.callback(isChecked); + }); + }, + ), + Text( + widget.label, + style: TextStyle(color: Colors.white), + ), + ], + ); + } +} diff --git a/lib/widgets/movies/filter_box.dart b/lib/widgets/movies/filter_box.dart new file mode 100644 index 0000000..4933a2f --- /dev/null +++ b/lib/widgets/movies/filter_box.dart @@ -0,0 +1,89 @@ +import 'package:flutter/material.dart'; +import 'package:multimedia/widgets/checkbox_with_label.dart'; + +import 'package:logger/logger.dart'; +import 'package:multimedia/log_printer.dart'; + +// ignore: must_be_immutable +class MovieFilterBox extends StatelessWidget { + MovieFilterBox({ + super.key, + required this.setFilter, + }); + + final Function( + String text, + bool showInit, + bool showProg, + bool showDone, + ) setFilter; + + bool initState = false; + bool progState = false; + bool doneState = false; + String searchText = ''; + + Logger logger = getLogger(); + + void initCallback(bool state) { + initState = state; + callSetFilter(); + } + + void progCallback(bool state) { + progState = state; + callSetFilter(); + } + + void doneCallback(bool state) { + doneState = state; + callSetFilter(); + } + + void textCallback(String text) { + searchText = text; + callSetFilter(); + } + + @override + Widget build(BuildContext context) { + return Row( + children: [ + const SizedBox( + width: 20, + ), + SizedBox( + width: 250, + child: TextField( + style: TextStyle(color: Colors.white), + decoration: InputDecoration( + labelText: 'Movie Title', + ), + onChanged: (text) { + textCallback(text); + }, + ), + ), + const SizedBox( + width: 20, + ), + CheckboxWithLabel( + label: 'Init', + callback: initCallback, + ), + CheckboxWithLabel( + label: 'Progress', + callback: progCallback, + ), + CheckboxWithLabel( + label: 'Done', + callback: doneCallback, + ), + ], + ); + } + + void callSetFilter() { + setFilter(searchText, initState, progState, doneState); + } +} diff --git a/lib/widgets/tvshows/filter_box.dart b/lib/widgets/tvshows/filter_box.dart new file mode 100644 index 0000000..b206119 --- /dev/null +++ b/lib/widgets/tvshows/filter_box.dart @@ -0,0 +1,89 @@ +import 'package:flutter/material.dart'; +import 'package:multimedia/widgets/checkbox_with_label.dart'; + +import 'package:logger/logger.dart'; +import 'package:multimedia/log_printer.dart'; + +// ignore: must_be_immutable +class TVShowFilterBox extends StatelessWidget { + TVShowFilterBox({ + super.key, + required this.setFilter, + }); + + final Function( + String text, + bool showInit, + bool showProg, + bool showDone, + ) setFilter; + + bool initState = false; + bool progState = false; + bool doneState = false; + String searchText = ''; + + Logger logger = getLogger(); + + void initCallback(bool state) { + initState = state; + callSetFilter(); + } + + void progCallback(bool state) { + progState = state; + callSetFilter(); + } + + void doneCallback(bool state) { + doneState = state; + callSetFilter(); + } + + void textCallback(String text) { + searchText = text; + callSetFilter(); + } + + @override + Widget build(BuildContext context) { + return Row( + children: [ + const SizedBox( + width: 20, + ), + SizedBox( + width: 250, + child: TextField( + style: TextStyle(color: Colors.white), + decoration: InputDecoration( + labelText: 'TVShow Title', + ), + onChanged: (text) { + textCallback(text); + }, + ), + ), + const SizedBox( + width: 20, + ), + CheckboxWithLabel( + label: 'Init', + callback: initCallback, + ), + CheckboxWithLabel( + label: 'Progress', + callback: progCallback, + ), + CheckboxWithLabel( + label: 'Done', + callback: doneCallback, + ), + ], + ); + } + + void callSetFilter() { + setFilter(searchText, initState, progState, doneState); + } +}