51 lines
1.2 KiB
Dart
51 lines
1.2 KiB
Dart
import 'package:didvan/constants/app_icons.dart';
|
|
import 'package:didvan/widgets/didvan/icon_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class BookmarkButton extends StatefulWidget {
|
|
final bool value;
|
|
final VoidCallback onMark;
|
|
final VoidCallback onUnmark;
|
|
final bool bigGestureSize;
|
|
const BookmarkButton({
|
|
Key? key,
|
|
required this.value,
|
|
required this.onMark,
|
|
required this.onUnmark,
|
|
this.bigGestureSize = false,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<BookmarkButton> createState() => _BookmarkButtonState();
|
|
}
|
|
|
|
class _BookmarkButtonState extends State<BookmarkButton> {
|
|
bool _value = false;
|
|
|
|
@override
|
|
void didUpdateWidget(covariant BookmarkButton oldWidget) {
|
|
_value = widget.value;
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
_value = widget.value;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DidvanIconButton(
|
|
gestureSize: widget.bigGestureSize ? 32 : 24,
|
|
icon: _value ? DidvanIcons.bookmark_solid : DidvanIcons.bookmark_regular,
|
|
onPressed: () {
|
|
setState(() {
|
|
_value = !_value;
|
|
});
|
|
_value ? widget.onMark() : widget.onUnmark();
|
|
},
|
|
);
|
|
}
|
|
}
|