Skip to content

Create detail news feature #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 60 additions & 47 deletions lib/feature/presentation/page/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter_news_app/feature/presentation/widget/widget_item_news.da
import 'package:flutter_news_app/injection_container.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';

class HomePage extends StatefulWidget {
@override
Expand Down Expand Up @@ -55,9 +56,6 @@ class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
ScreenUtil.init(context);
var mediaQueryData = MediaQuery.of(context);
var paddingTop = mediaQueryData.padding.top;
var paddingBottom = mediaQueryData.padding.bottom;
return Scaffold(
body: BlocProvider<TopHeadlinesNewsBloc>(
create: (context) => topHeadlinesNewsBloc,
Expand All @@ -78,53 +76,62 @@ class _HomePageState extends State<HomePage> {
}
}
},
child: Container(
width: double.infinity,
color: Color(0xFFEFF5F5),
padding: EdgeInsets.symmetric(
vertical: 24.h,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: paddingTop),
Padding(
padding: EdgeInsets.symmetric(horizontal: 48.w),
child: Row(
child: Stack(
children: [
Container(
width: double.infinity,
height: double.infinity,
color: Color(0xFFEFF5F5),
),
SafeArea(
child: Container(
width: double.infinity,
color: Color(0xFFEFF5F5),
padding: EdgeInsets.symmetric(
vertical: 24.h,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
'Daily News',
style: TextStyle(
fontSize: 48.sp,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 48.w),
child: Row(
children: <Widget>[
Expanded(
child: Text(
'Daily News',
style: TextStyle(
fontSize: 48.sp,
),
),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SearchPage()),
);
},
child: Hero(
tag: 'iconSearch',
child: Icon(Icons.search),
),
),
],
),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SearchPage()),
);
},
child: Hero(
tag: 'iconSearch',
child: Icon(Icons.search),
),
WidgetDateToday(),
SizedBox(height: 24.h),
WidgetCategoryNews(listCategories: listCategories),
SizedBox(height: 24.h),
Expanded(
child: Platform.isIOS ? _buildWidgetContentNewsIOS() : _buildWidgetContentNewsAndroid(),
),
],
),
),
WidgetDateToday(),
SizedBox(height: 24.h),
WidgetCategoryNews(listCategories: listCategories),
SizedBox(height: 24.h),
Expanded(
child: Platform.isIOS ? _buildWidgetContentNewsIOS() : _buildWidgetContentNewsAndroid(),
),
SizedBox(height: paddingBottom),
],
),
),
],
),
),
),
Expand Down Expand Up @@ -287,12 +294,18 @@ class _HomePageState extends State<HomePage> {
String strPublishedAt,
) {
return GestureDetector(
onTap: () {
// TODO: buat fitur arahkan ke website detail berita
onTap: () async {
if (await canLaunch(itemArticle.url)) {
await launch(itemArticle.url);
} else {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Couldn\'t open detail news'),
));
}
},
child: Container(
width: double.infinity,
height: ScreenUtil.screenHeightDp / 3,
height: ScreenUtil.screenWidthDp / 1.7,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
image: DecorationImage(
Expand All @@ -306,7 +319,7 @@ class _HomePageState extends State<HomePage> {
children: <Widget>[
Container(
width: double.infinity,
height: ScreenUtil.screenHeightDp / 3,
height: ScreenUtil.screenWidthDp / 1.7,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
gradient: LinearGradient(
Expand Down
213 changes: 110 additions & 103 deletions lib/feature/presentation/page/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,119 +42,126 @@ class _SearchPageState extends State<SearchPage> {
@override
Widget build(BuildContext context) {
ScreenUtil.init(context);
var mediaQueryData = MediaQuery.of(context);
var paddingTop = mediaQueryData.padding.top;
var paddingBottom = mediaQueryData.padding.bottom;
return Scaffold(
body: BlocProvider<TopHeadlinesNewsBloc>(
create: (context) => topHeadlinesNewsBloc,
child: Container(
color: Color(0xFFEFF5F5),
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 48.w,
vertical: 24.h,
),
child: Column(
children: <Widget>[
SizedBox(height: paddingTop),
Row(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(
Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
),
),
SizedBox(width: 24.w),
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(99.0),
),
padding: EdgeInsets.symmetric(horizontal: 36.w),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: controllerKeyword,
decoration: InputDecoration(
isDense: true,
hintText: 'Searching something?',
hintStyle: TextStyle(
fontSize: 36.sp,
color: Colors.grey,
),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
style: TextStyle(
fontSize: 36.sp,
),
),
child: Stack(
children: [
Container(
width: double.infinity,
height: double.infinity,
color: Color(0xFFEFF5F5),
),
SafeArea(
child: Container(
color: Color(0xFFEFF5F5),
width: double.infinity,
padding: EdgeInsets.symmetric(
vertical: 24.h,
horizontal: 48.w,
),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(
Platform.isIOS ? Icons.arrow_back_ios : Icons.arrow_back,
),
Hero(
tag: 'iconSearch',
child: Focus(
focusNode: focusNodeIconSearch,
child: Icon(
Icons.search,
size: 48.w,
),
),
SizedBox(width: 24.w),
Expanded(
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(99.0),
),
padding: EdgeInsets.symmetric(horizontal: 36.w),
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: controllerKeyword,
decoration: InputDecoration(
isDense: true,
hintText: 'Searching something?',
hintStyle: TextStyle(
fontSize: 36.sp,
color: Colors.grey,
),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
style: TextStyle(
fontSize: 36.sp,
),
),
),
Hero(
tag: 'iconSearch',
child: Focus(
focusNode: focusNodeIconSearch,
child: Icon(
Icons.search,
size: 48.w,
),
),
),
],
),
),
],
),
),
],
),
),
],
),
SizedBox(height: 16.h),
Expanded(
child: BlocBuilder<TopHeadlinesNewsBloc, TopHeadlinesNewsState>(
builder: (context, state) {
if (state is LoadingTopHeadlinesNewsState) {
return Center(
child: Platform.isIOS ? CupertinoActivityIndicator() : CircularProgressIndicator(),
);
} else if (state is FailureTopHeadlinesNewsState) {
return WidgetFailureMessage();
} else if (state is SearchSuccessTopHeadlinesNewsState) {
var listArticles = state.listArticles;
if (listArticles.isEmpty) {
return WidgetFailureMessage(
errorTitle: 'Data not found',
errorSubtitle: 'Hm, we couldn\'t find what you were looking for.',
);
} else {
return ListView.builder(
padding: EdgeInsets.only(bottom: paddingBottom),
itemBuilder: (context, index) {
var itemArticle = listArticles[index];
var dateTimePublishedAt =
DateFormat('yyy-MM-ddTHH:mm:ssZ').parse(itemArticle.publishedAt, true);
var strPublishedAt = DateFormat('MMM dd, yyyy HH:mm').format(dateTimePublishedAt);
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.h),
child: WidgetItemNews(
itemArticle: itemArticle,
strPublishedAt: strPublishedAt,
),
SizedBox(height: 16.h),
Expanded(
child: BlocBuilder<TopHeadlinesNewsBloc, TopHeadlinesNewsState>(
builder: (context, state) {
if (state is LoadingTopHeadlinesNewsState) {
return Center(
child: Platform.isIOS ? CupertinoActivityIndicator() : CircularProgressIndicator(),
);
},
itemCount: listArticles.length,
);
}
}
return Container();
},
} else if (state is FailureTopHeadlinesNewsState) {
return WidgetFailureMessage();
} else if (state is SearchSuccessTopHeadlinesNewsState) {
var listArticles = state.listArticles;
if (listArticles.isEmpty) {
return WidgetFailureMessage(
errorTitle: 'Data not found',
errorSubtitle: 'Hm, we couldn\'t find what you were looking for.',
);
} else {
return ListView.builder(
padding: EdgeInsets.zero,
itemBuilder: (context, index) {
var itemArticle = listArticles[index];
var dateTimePublishedAt =
DateFormat('yyy-MM-ddTHH:mm:ssZ').parse(itemArticle.publishedAt, true);
var strPublishedAt = DateFormat('MMM dd, yyyy HH:mm').format(dateTimePublishedAt);
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.h),
child: WidgetItemNews(
itemArticle: itemArticle,
strPublishedAt: strPublishedAt,
),
);
},
itemCount: listArticles.length,
);
}
}
return Container();
},
),
),
],
),
),
],
),
),
],
),
),
);
Expand Down
Loading