Skip to content

Commit

Permalink
Improve UI and Added feature to see Image when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
insfirred committed Jun 16, 2022
1 parent 3e207f0 commit ad6fdd7
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 52 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Binary file added assets/images/unavailable-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions lib/HomeScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class HomeScreen extends StatefulWidget {
}

class _HomeScreenState extends State<HomeScreen> {

var controller = PageController(initialPage: 1);
late PageController controller;

String url = "https://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=ff7aefdd16e6480faf2817f36e2daa5e";

Expand All @@ -35,9 +34,9 @@ class _HomeScreenState extends State<HomeScreen> {
}

@override

void initState() {
super.initState();
controller = PageController(initialPage: 1);
fetchNews();
}

Expand All @@ -53,10 +52,6 @@ class _HomeScreenState extends State<HomeScreen> {
WebView(),
],
),
// floatingActionButton: FloatingActionButton(
// onPressed: ()=> fetchNews(),
// child: Icon(Icons.search),
// ),
),
);
}
Expand Down
93 changes: 51 additions & 42 deletions lib/Screens/newsList.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

import './showImage.dart';
import '../animation/animation.dart';

class NewsList extends StatelessWidget {

var jsonData;
NewsList(this.jsonData);

Expand All @@ -19,50 +21,57 @@ class NewsList extends StatelessWidget {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height / 3,
color: Colors.amber,
// child: Image(
// fit: BoxFit.fill,
// image: AssetImage('assets/images/img.png')
// image: NetworkImage,
// ),
child: Image.network("${jsonData["articles"][index]["urlToImage"]}", fit: BoxFit.fill,),
InkWell(
// onTap: () => Navigator.push(context, MaterialPageRoute(builder: (context)=> ShowImage("${jsonData["articles"][index]["urlToImage"]}"))),
onTap: () =>
Navigator.push(context, SizeTransition3(ShowImage("${jsonData["articles"][index]["urlToImage"]}"))),
child: SizedBox(
height: MediaQuery.of(context).size.height / 3,
child: (jsonData["articles"][index]["urlToImage"] != null)
? Image.network(
"${jsonData["articles"][index]["urlToImage"]}",
fit: BoxFit.fill,
)
: const Image(image: AssetImage('assets/images/unavailable-image.jpg'))
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
jsonData["articles"][index]["title"],
style: TextStyle(fontSize: 25),
textAlign: TextAlign.justify),
const SizedBox(height: 10),
Text(
(jsonData["articles"][index]["content"] != null) ?jsonData["articles"][index]["content"] :"",
style: TextStyle(
color: Colors.grey[600], fontSize: 17),
textAlign: TextAlign.justify,
),
SizedBox(height: 15),
Text(
'Published at: ${dateFormatter.format( DateTime.parse(jsonData["articles"][index]["publishedAt"]))} ${timeFormatter.format( DateTime.parse(jsonData["articles"][index]["publishedAt"]))}',
style: TextStyle(color: Colors.grey, fontSize: 16),
textAlign: TextAlign.justify,
),
SizedBox(height: 20,),
Text(
'swipe left for more info.',
style: TextStyle(color: Colors.grey, fontSize: 14),
textAlign: TextAlign.justify,
),
],
child: Container(
padding: EdgeInsets.all(15),
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(18)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
jsonData["articles"][index]["title"],
style: TextStyle(fontSize: 25),
textAlign: TextAlign.justify),
const SizedBox(height: 10),
Text(
(jsonData["articles"][index]["content"] != null)
? jsonData["articles"][index]["content"]
: "",
style: TextStyle(color: Colors.grey[600], fontSize: 17),
textAlign: TextAlign.justify,
),
SizedBox(height: 15),
Text(
'Published at: ${dateFormatter.format(DateTime.parse(jsonData["articles"][index]["publishedAt"]))} ${timeFormatter.format(DateTime.parse(jsonData["articles"][index]["publishedAt"]))}',
style: TextStyle(color: Colors.grey, fontSize: 16),
textAlign: TextAlign.justify,
),
SizedBox(
height: 20,
),
Text(
'swipe left for more info.',
style: TextStyle(color: Colors.grey, fontSize: 14),
textAlign: TextAlign.justify,
),
))
],
),
))
],
);
});
Expand Down
16 changes: 16 additions & 0 deletions lib/Screens/showImage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

class ShowImage extends StatelessWidget {
String url;
ShowImage(this.url);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: (url != "null")
?Center(child: Image.network(url))
:Center(child: Text("Image Unavailable !",style: TextStyle(color: Colors.white),)),
);
}
}
3 changes: 2 additions & 1 deletion lib/Screens/waitingScreen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class WaitingScreen extends StatefulWidget {
const WaitingScreen({Key? key}) : super(key: key);
Expand All @@ -16,7 +17,7 @@ class _WaitingScreenState extends State<WaitingScreen> {
Icon(Icons.cloud_outlined,size: 150,),
Icon(Icons.arrow_downward_rounded,size: 65,),
SizedBox(height: 15),
Icon(Icons.mobile_friendly_rounded,size: 130,),
Icon(FontAwesomeIcons.mobileScreen,size: 115,),
SizedBox(height: 50,),
Text('Loading Shorts...',style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),),
SizedBox(height: 40,),
Expand Down
28 changes: 28 additions & 0 deletions lib/animation/animation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';

class SizeTransition3 extends PageRouteBuilder {
final Widget page;

SizeTransition3(this.page)
: super(
pageBuilder: (context, animation, anotherAnimation) => page,
transitionDuration: Duration(milliseconds: 1000),
reverseTransitionDuration: Duration(milliseconds: 200),
transitionsBuilder: (context, animation, anotherAnimation, child) {
animation = CurvedAnimation(
curve: Curves.fastLinearToSlowEaseIn,
parent: animation,
reverseCurve: Curves.fastOutSlowIn);
return Align(
alignment: Alignment.center,
child: SizeTransition(
axis: Axis.horizontal,
sizeFactor: animation,
child: page,
axisAlignment: 0,
),
);
},
);

}
7 changes: 5 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import 'package:flutter/material.dart';
import './HomeScreen.dart';

void main() {
runApp(MaterialApp(
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
themeMode: ThemeMode.system,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: HomeScreen(),
));
)
);
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
font_awesome_flutter:
dependency: "direct main"
description:
name: font_awesome_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "10.1.0"
http:
dependency: "direct main"
description:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies:
cupertino_icons: ^1.0.2
http: ^0.13.4
intl: ^0.17.0
font_awesome_flutter: ^10.1.0

dev_dependencies:
flutter_test:
Expand All @@ -62,6 +63,8 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/img.png
- assets/images/unavailable-image.jpg

# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down

0 comments on commit ad6fdd7

Please sign in to comment.