2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-23 00:18:24 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../themes/stack_colors.dart';
|
|
|
|
import '../../themes/theme_providers.dart';
|
|
|
|
import '../../utilities/assets.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-09-23 00:18:24 +00:00
|
|
|
class FavoriteToggle extends ConsumerStatefulWidget {
|
2022-08-26 08:11:35 +00:00
|
|
|
const FavoriteToggle({
|
|
|
|
Key? key,
|
|
|
|
this.backGround,
|
|
|
|
this.borderRadius = BorderRadius.zero,
|
|
|
|
this.initialState = false,
|
2022-09-21 00:46:07 +00:00
|
|
|
this.on,
|
|
|
|
this.off,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.onChanged,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final Color? backGround;
|
2022-09-21 00:46:07 +00:00
|
|
|
final Color? on;
|
|
|
|
final Color? off;
|
2022-08-26 08:11:35 +00:00
|
|
|
final BorderRadiusGeometry borderRadius;
|
|
|
|
final bool initialState;
|
|
|
|
final void Function(bool)? onChanged;
|
|
|
|
|
|
|
|
@override
|
2022-09-23 00:18:24 +00:00
|
|
|
ConsumerState<FavoriteToggle> createState() => _FavoriteToggleState();
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 00:18:24 +00:00
|
|
|
class _FavoriteToggleState extends ConsumerState<FavoriteToggle> {
|
2022-08-26 08:11:35 +00:00
|
|
|
late bool _isActive;
|
|
|
|
late Color _color;
|
|
|
|
late void Function(bool)? _onChanged;
|
|
|
|
|
2022-09-21 00:46:07 +00:00
|
|
|
late final Color on;
|
|
|
|
late final Color off;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-04-24 14:36:12 +00:00
|
|
|
on = widget.on ?? ref.read(themeProvider.state).state.favoriteStarActive;
|
|
|
|
off =
|
|
|
|
widget.off ?? ref.read(themeProvider.state).state.favoriteStarInactive;
|
2022-08-26 08:11:35 +00:00
|
|
|
_isActive = widget.initialState;
|
2022-09-21 00:46:07 +00:00
|
|
|
_color = _isActive ? on : off;
|
2022-08-26 08:11:35 +00:00
|
|
|
_onChanged = widget.onChanged;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: widget.backGround,
|
|
|
|
borderRadius: widget.borderRadius,
|
|
|
|
),
|
|
|
|
child: MaterialButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
2022-08-26 08:11:35 +00:00
|
|
|
minWidth: 0,
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: widget.borderRadius,
|
|
|
|
),
|
|
|
|
onPressed: _onChanged != null
|
|
|
|
? () {
|
|
|
|
_isActive = !_isActive;
|
|
|
|
setState(() {
|
2022-09-21 00:46:07 +00:00
|
|
|
_color = _isActive ? on : off;
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
_onChanged!.call(_isActive);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.star,
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
color: _color,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|