simple_quotes_plus 1.0.0
simple_quotes_plus: ^1.0.0 copied to clipboard
A Dart package for accessing motivational, love, and wisdom quotes.lling and animation.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:simple_quotes_plus/simple_quotes_plus.dart';
import 'widgets/quote_card.dart';
void main() {
runApp(const QuoteApp());
}
class QuoteApp extends StatelessWidget {
const QuoteApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Quotes App',
theme: ThemeData(primarySwatch: Colors.teal),
home: const QuoteHomePage(),
);
}
}
class QuoteHomePage extends StatefulWidget {
const QuoteHomePage({super.key});
@override
State<QuoteHomePage> createState() => _QuoteHomePageState();
}
class _QuoteHomePageState extends State<QuoteHomePage> {
final QuoteRepository repo = QuoteRepository();
List<Quote> displayedQuotes = [];
String? selectedCategory;
String searchQuery = '';
@override
void initState() {
super.initState();
displayedQuotes = [repo.getRandom()];
}
void _filterByCategory(String? category) {
setState(() {
selectedCategory = category;
displayedQuotes = category == null
? repo.getAll()
: repo.getAll().where((q) => q.category == category).toList();
});
}
void _searchQuotes(String query) {
setState(() {
searchQuery = query;
displayedQuotes = repo.search(query);
});
}
@override
Widget build(BuildContext context) {
final categories = repo.getCategories();
return Scaffold(
appBar: AppBar(
title: const Text('Simple Quotes'),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(56),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: TextField(
onChanged: _searchQuotes,
decoration: InputDecoration(
hintText: 'Search quotes...',
prefixIcon: const Icon(Icons.search),
filled: true,
fillColor: Colors.white,
contentPadding: const EdgeInsets.all(12),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
),
),
),
),
body: Column(
children: [
Wrap(
spacing: 8,
children: [
ChoiceChip(
label: const Text('All'),
selected: selectedCategory == null,
onSelected: (_) => _filterByCategory(null),
),
...categories.map((cat) => ChoiceChip(
label: Text(cat),
selected: selectedCategory == cat,
onSelected: (_) => _filterByCategory(cat),
)),
],
),
const SizedBox(height: 8),
Expanded(
child: ListView.builder(
itemCount: displayedQuotes.length,
itemBuilder: (context, index) =>
QuoteCard(quote: displayedQuotes[index]),
),
)
],
),
);
}
}