Files
bini-google-tv/flutter_app/lib/widgets/bible_verse_widget.dart

109 lines
3.3 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.symmetric(horizontal: 12, vertical: 20), // Reduced horizontal padding
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: [
// Quote icon removed as requested
Expanded(
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600), // Increased width to utilize space
child: Text(
verse.text.replaceAll('\\n', '\n'), // Just handle line breaks, keep original text
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 36,
height: 1.4,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
const SizedBox(height: 12),
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
verse.reference,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: 24, // Reduced from 32
fontWeight: FontWeight.bold,
),
),
),
],
);
},
),
);
}
}