creta_news 0.1.0
creta_news: ^0.1.0 copied to clipboard
Beautiful Headline News widget using Google News RSS for Flutter (Web, Windows, Android).
example/lib/main.dart
import 'package:creta_news/creta_news.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const DemoApp());
}
class DemoApp extends StatefulWidget {
const DemoApp({super.key});
@override
State<DemoApp> createState() => _DemoAppState();
}
class _DemoAppState extends State<DemoApp> {
ThemeMode _mode = ThemeMode.light;
Nation _nation = Nation.korea;
bool _showTitle = true;
bool _showDate = true;
int _count = 5;
final _controller = CretaHeadlineNewsController();
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Creta News Demo',
themeMode: _mode,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: Scaffold(
appBar: AppBar(
title: const Text('Creta Headline News Demo'),
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: _controller.refresh,
tooltip: 'Refresh',
),
IconButton(
icon: const Icon(Icons.brightness_6),
onPressed: () => setState(() {
_mode = _mode == ThemeMode.light ? ThemeMode.dark : ThemeMode.light;
}),
tooltip: 'Toggle theme',
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(12),
child: Wrap(
spacing: 12,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
DropdownButton<Nation>(
value: _nation,
onChanged: (v) => setState(() => _nation = v ?? Nation.korea),
items: const [
DropdownMenuItem(value: Nation.korea, child: Text('Korea')),
DropdownMenuItem(value: Nation.usa, child: Text('USA')),
DropdownMenuItem(value: Nation.japan, child: Text('Japan')),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Show Title'),
Switch(value: _showTitle, onChanged: (v) => setState(() => _showTitle = v)),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Show Date'),
Switch(value: _showDate, onChanged: (v) => setState(() => _showDate = v)),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Count'),
Slider(
value: _count.toDouble(),
min: 1,
max: 10,
divisions: 9,
label: '$_count',
onChanged: (v) => setState(() => _count = v.toInt()),
),
],
),
],
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(16),
child: CretaHeadlineNews(
width: 700,
height: double.infinity,
nation: _nation,
newsLineCount: _count,
showTitle: _showTitle,
titleText: 'Top Headlines',
showDate: _showDate,
controller: _controller,
),
),
),
],
),
),
),
);
}
}