update
This commit is contained in:
@@ -21,18 +21,6 @@ class ShopUI extends StatelessWidget {
|
||||
final player = battleProvider.player;
|
||||
final shopItems = shopProvider.availableItems;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (shopProvider.lastShopMessage.isNotEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(shopProvider.lastShopMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
shopProvider.clearMessage();
|
||||
}
|
||||
});
|
||||
|
||||
return Container(
|
||||
color: ThemeConfig.shopBg,
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
@@ -139,6 +127,7 @@ class ShopUI extends StatelessWidget {
|
||||
width: 48,
|
||||
height: 48,
|
||||
fit: BoxFit.contain,
|
||||
filterQuality: FilterQuality.high,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -154,7 +143,8 @@ class ShopUI extends StatelessWidget {
|
||||
color: ItemUtils.getRarityColor(
|
||||
item.rarity,
|
||||
),
|
||||
fontSize: ThemeConfig.fontSizeMedium,
|
||||
fontSize:
|
||||
ThemeConfig.fontSizeMedium,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
@@ -215,10 +205,20 @@ class ShopUI extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
onPressed: player.gold >= GameConfig.shopRerollCost
|
||||
? () => shopProvider.rerollShopItems(
|
||||
player,
|
||||
battleProvider.stage,
|
||||
)
|
||||
? () {
|
||||
bool success = shopProvider.rerollShopItems(
|
||||
player,
|
||||
battleProvider.stage,
|
||||
);
|
||||
if (!success) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("Not enough gold to reroll!"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(
|
||||
Icons.refresh,
|
||||
@@ -287,8 +287,33 @@ class ShopUI extends StatelessWidget {
|
||||
backgroundColor: ThemeConfig.statGoldColor,
|
||||
),
|
||||
onPressed: () {
|
||||
shopProvider.buyItem(item, player);
|
||||
Navigator.pop(ctx);
|
||||
bool success = shopProvider.buyItem(item, player);
|
||||
Navigator.pop(ctx); // Close dialog first
|
||||
|
||||
if (success) {
|
||||
// Refresh BattleProvider to update UI (Gold, Inventory) since player object is owned by BattleProvider
|
||||
// and ShopProvider modifies it directly without BattleProvider knowing.
|
||||
// Ideally, ShopProvider should notify, but since we don't have a direct link back or a shared PlayerProvider,
|
||||
// we trigger it from the UI.
|
||||
// Alternatively, we could add refreshUI to BattleProvider.
|
||||
// Assuming BattleProvider has refreshUI or we can just use notifyListeners if we had access, but we don't.
|
||||
// Wait, we have battleProvider instance passed to ShopUI.
|
||||
battleProvider.refreshUI();
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Bought ${item.name}"),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(shopProvider.lastShopMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text("Buy", style: TextStyle(color: Colors.black)),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user