Redesigned
This commit is contained in:
67
lib/components/favoriteButton.dart
Normal file
67
lib/components/favoriteButton.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../settings.dart';
|
||||
import 'menuiButton.dart';
|
||||
|
||||
class FavoriteButton extends StatefulWidget {
|
||||
final String id;
|
||||
|
||||
FavoriteButton({@required this.id, Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_FavoriteButtonState createState() => _FavoriteButtonState();
|
||||
}
|
||||
|
||||
class _FavoriteButtonState extends State<FavoriteButton> {
|
||||
final MenuiSettings settings = new MenuiSettings();
|
||||
Future<bool> isInFavorites;
|
||||
bool inFavorites = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
isInFavorites = settings.isInFavorites(widget.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => FutureBuilder(
|
||||
initialData: false,
|
||||
future: isInFavorites,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
inFavorites = snapshot.data;
|
||||
if (inFavorites) {
|
||||
return MenuiButton(
|
||||
color: Colors.orange,
|
||||
icon: Icons.favorite_rounded,
|
||||
text: "Usuń",
|
||||
onPressed: () {
|
||||
settings.addToFavorites(widget.id);
|
||||
setState(() {
|
||||
isInFavorites = settings.isInFavorites(widget.id);
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return MenuiButton(
|
||||
color: Colors.grey,
|
||||
icon: Icons.favorite_rounded,
|
||||
text: "Dodaj",
|
||||
onPressed: () {
|
||||
settings.addToFavorites(widget.id);
|
||||
setState(() {
|
||||
isInFavorites = settings.isInFavorites(widget.id);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return MenuiButton(
|
||||
color: Colors.grey,
|
||||
icon: Icons.favorite_rounded,
|
||||
text: "Dodaj",
|
||||
onPressed: () {},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user