class WalletPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Wallets')),
body: BlocBuilder<WalletBloc, WalletState>(
builder: (context, state) {
if (state is WalletInitial) {
return Center(child: Text('Press button to load'));
}
if (state is WalletLoading) {
return Center(child: CircularProgressIndicator());
}
if (state is WalletLoaded) {
return ListView.builder(
itemCount: state.wallets.length,
itemBuilder: (context, index) {
final wallet = state.wallets[index];
return ListTile(
title: Text(wallet.name),
subtitle: Text('${wallet.balance} ${wallet.currency}'),
);
},
);
}
if (state is WalletError) {
return Center(child: Text('Error: ${state.message}'));
}
return Container();
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
context.read<WalletBloc>().add(LoadWallets());
},
child: Icon(Icons.refresh),
),
);
}
}