Files
bini-google-tv/flutter_app/lib/widgets/bible_verse_widget.dart
2026-01-24 23:45:22 +09:00

98 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/bible_verse.dart';
import '../services/bible_service.dart';
class BibleVerseWidget extends StatefulWidget {
const BibleVerseWidget({super.key});
@override
State<BibleVerseWidget> createState() => _BibleVerseWidgetState();
}
class _BibleVerseWidgetState extends State<BibleVerseWidget> {
late Future<BibleVerse> _verseFuture;
@override
void initState() {
super.initState();
// Fetch only once on init
_verseFuture = Provider.of<BibleService>(
context,
listen: false,
).fetchTodayVerse();
}
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).cardTheme.color!.withOpacity(0.8),
Theme.of(context).cardTheme.color!,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.white10),
),
padding: const EdgeInsets.all(24),
child: FutureBuilder<BibleVerse>(
future: _verseFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return const Center(
child: Text(
'Verse Unavailable',
style: TextStyle(color: Colors.white54),
),
);
}
if (!snapshot.hasData) {
return const SizedBox.shrink();
}
final verse = snapshot.data!;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.format_quote,
color: Color(0xFFBB86FC),
size: 32,
),
const SizedBox(height: 12),
Text(
verse.text,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.white,
height: 1.5,
fontStyle: FontStyle.italic,
),
),
const SizedBox(height: 8),
Text(
verse.reference,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
],
);
},
),
);
}
}