Adding TopNews

This commit is contained in:
2021-03-25 10:54:09 +02:00
parent ce237c13a4
commit e290274a95
17 changed files with 510 additions and 50 deletions
+130
View File
@@ -0,0 +1,130 @@
import 'package:flutter/material.dart';
import 'package:le_kiosque_by_gcs/model/news.dart';
class ItemRegularNews extends StatelessWidget {
const ItemRegularNews({Key key, this.news}) : super(key: key);
final News news;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 12, right: 12),
child: InkWell(
onTap: () {
_showDetailNews(context);
},
child: Card(
elevation: 4,
child: Container(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.grey,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
image: DecorationImage(
image: NetworkImage(news.previewUrl),
fit: BoxFit.cover,
),
),
),
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 10),
child: Text(
news.title,
textAlign: TextAlign.justify,
overflow: TextOverflow.ellipsis,
maxLines: 3,
style: TextStyle(
fontSize: 15,
color: Colors.black,
),
),
),
SizedBox(height: 14),
SizedBox(
height: 16,
child: Image.network(news.sourceUrl),
)
],
),
)
],
),
),
),
),
);
return InkWell(
onTap: () {
_showDetailNews(context);
},
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 16),
child: Card(
elevation: 4,
child: Container(
width: double.infinity,
height: 120,
child: Row(
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.grey,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
image: DecorationImage(
image: NetworkImage(news.previewUrl),
fit: BoxFit.cover,
),
),
),
Column(
children: [
Padding(
padding: EdgeInsets.all(16.0),
child: Text(
news.title,
overflow: TextOverflow.ellipsis,
maxLines: 4,
style: TextStyle(
fontSize: 17,
color: Colors.black,
),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Image.network(news.sourceUrl),
)
],
)
],
),
),
),
),
);
}
void _showDetailNews(BuildContext context) {}
}
+85
View File
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:le_kiosque_by_gcs/model/news.dart';
import 'package:url_launcher/url_launcher.dart';
class ItemTopNews extends StatelessWidget {
const ItemTopNews({Key key, this.news}) : super(key: key);
final News news;
@override
Widget build(BuildContext context) {
return Container(
height: 259,
width: 270,
child: InkWell(
onTap: () {
_showFullArticle(context, news.fullPostUrl);
},
child: Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
height: 259,
width: 270,
decoration: BoxDecoration(
color: Colors.grey,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
image: DecorationImage(
image: NetworkImage(news.previewUrl),
fit: BoxFit.cover,
),
),
),
Container(
height: 259,
width: 270,
decoration: BoxDecoration(
color: Colors.black38,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
news.title,
maxLines: 4,
style: TextStyle(
fontSize: 17,
color: Colors.white,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 16, bottom: 16),
child: SizedBox(
height: 16,
child: Image.network(news.sourceUrl),
),
)
],
),
],
),
),
);
}
void _showFullArticle(BuildContext context, String fullPostUrl) async {
if (await canLaunch(fullPostUrl)) {
await launch(fullPostUrl);
} else {
throw 'Could not launch $fullPostUrl';
}
}
}
+74
View File
@@ -0,0 +1,74 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:le_kiosque_by_gcs/model/magazine.dart';
import 'package:le_kiosque_by_gcs/model/news.dart';
import 'package:le_kiosque_by_gcs/ui/view/news/item_regular_news.dart';
import 'package:le_kiosque_by_gcs/ui/view/news/item_top_news.dart';
class NewsView extends StatelessWidget {
const NewsView({
Key key,
@required this.newsList,
}) : super(key: key);
final List<News> newsList;
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: [
SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverToBoxAdapter(
child: Text(
"Top actualité",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF3B3B3B),
),
),
),
),
SliverToBoxAdapter(
child: Container(
height: 280,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: magazinesTest.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
left: 16,
bottom: 16,
),
child: ItemTopNews(
news: newsList[index],
),
);
},
),
),
),
SliverPadding(
padding: EdgeInsets.all(16),
sliver: SliverToBoxAdapter(
child: Text(
"Actualité de la semaine",
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF3B3B3B),
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return ItemRegularNews(news: newsList[index]);
}, childCount: newsList.length),
),
],
);
}
}