Skip to content

Commit

Permalink
bottomNavigation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkumarsingh1991 committed Sep 8, 2018
1 parent 3dfe81a commit 547d8a3
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 210 deletions.
12 changes: 2 additions & 10 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

313 changes: 190 additions & 123 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions lib/containers/NewsMoreDetails.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class NewsMoreDetails extends StatelessWidget {

Expand All @@ -11,16 +10,6 @@ class NewsMoreDetails extends StatelessWidget {
theme: new ThemeData(
primarySwatch: Colors.blue,
),
routes: {
'/widget': (_) => new WebviewScaffold(
url: 'google.com',
appBar: new AppBar(
title: const Text('Widget webview'),
),
withZoom: true,
withLocalStorage: true,
)
},
);
}
}
Expand Down
98 changes: 45 additions & 53 deletions lib/containers/PackageDetails.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:my_app/widgets/Workspace.dart';
import 'package:my_app/containers/NewsMoreDetails.dart';
import 'package:my_app/widgets/BookMarked.dart';
import 'package:my_app/widgets/HomeNewsList.dart';
import 'package:my_app/widgets/NewsSort.dart';


class PackageDetails extends StatefulWidget{
@override
Expand All @@ -24,65 +23,58 @@ class PackageDetails extends StatefulWidget{
//}

class PackageDetail extends State<PackageDetails> {
List data;
Future<List> fetchPost(String category) async {
final String url = 'https://newsapi.org/v2/top-headlines?country=in&category=${category}&apiKey=3049e63f96e143f3be070d8f031f68d6';
final response = await http.get(url);
if (response.statusCode == 200) {
List list = json.decode(response.body)['articles'];
this.setState(() {
data = list;
});
return list;
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
int _currentIndex = 0;
final List<Widget> _children = [
HomeNewsList(),
BookMarked(),
NewsSort()
];
void onTabTapped(int index) {
print('checiign');
setState(() {
_currentIndex = index;
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
this.fetchPost('sport');
// this.fetchPost('sport');
}

@override
Widget build(BuildContext context) {
String url = 'https://c.ndtvimg.com/2018-09/0pvfjoro_jasprit-bumrah-reuters_625x300_08_September_18.jpg';
return Scaffold(
appBar: AppBar(
title: Text("Package Details"),
),
body: Container(
child: this.data != null ? ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context, int index){
return new Card(
child: Column(
children: <Widget>[
new GestureDetector(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => NewsMoreDetails()),
);
},child: Column(
children: <Widget>[
new Image.network(data[index]['urlToImage'] == null ? url : data[index]['urlToImage'],fit: BoxFit.fill),
new Text(data[index]['description'] == null ? 'not found' : data[index]['description']),
],
),
)

],
// footer button
bottomNavigationBar: new Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.blue,
primaryColor: Colors.red,
), // sets the inactive color of the `BottomNavigationBar`
child: new BottomNavigationBar(
onTap: onTabTapped,
currentIndex: _currentIndex,
items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.menu),
title: new Text("Home"),
),

);
},

) : new WorkSpace(),// DATA LOADER

)
new BottomNavigationBarItem(
icon: new Icon(Icons.book),
title: new Text("save"),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.sort),
title: new Text("sort"),
),
],
),
),
body: new Stack(
children: <Widget>[
_children[_currentIndex],
],
)

);
}
Expand Down
16 changes: 16 additions & 0 deletions lib/styles/styles.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';

Map<String, TextStyle> textStyles = {
'title': new TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
textBaseline: TextBaseline.alphabetic,
color: Colors.blueAccent,
),
'disc': new TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.normal,
fontStyle: FontStyle.normal,
textBaseline: TextBaseline.alphabetic,
),
};
20 changes: 20 additions & 0 deletions lib/widgets/BookMarked.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class BookMarked extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
appBar: AppBar(
title: Text("BookMarked"),
backgroundColor: Colors.blue,
);
return Container(
child: new Center (
child: Text('Bookmarked'),
),

);
}
}
1 change: 1 addition & 0 deletions lib/widgets/DemoWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Widget build(BuildContext context){
);
},
child: new Text("NextPage"),

));
}
}
111 changes: 111 additions & 0 deletions lib/widgets/HomeNewsList.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:my_app/widgets/Workspace.dart';
import 'package:my_app/styles/styles.dart';

class HomeNewsList extends StatefulWidget{
@override
HomeNews createState() => HomeNews();
}

class HomeNews extends State<HomeNewsList>{
List data;
Future<List> fetchPost(String category) async {
final String url = 'https://newsapi.org/v2/top-headlines?country=in&category=${category}&apiKey=3049e63f96e143f3be070d8f031f68d6';
final response = await http.get(url);
if (response.statusCode == 200) {
List list = json.decode(response.body)['articles'];
this.setState(() {
data = list;
});
return list;
} else {
// If that call was not successful, throw an error.
throw Exception('Failed to load post');
}
}
@override
void initState() {
// TODO: implement initState
super.initState();
this.fetchPost('sport');
}
@override
Widget build(BuildContext context) {
// TODO: implement build
String url = 'https://c.ndtvimg.com/2018-09/0pvfjoro_jasprit-bumrah-reuters_625x300_08_September_18.jpg';
return Scaffold(
appBar: AppBar(
title: Text("Home"),
backgroundColor: Colors.blue,
),
body: Container(
color: Colors.black26,
child: this.data != null ? ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context, int index){
return new Card(
margin: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
new Container(
padding: EdgeInsets.all(5.0),
child: Row(
children: <Widget>[
new Container(
width: 270.0,
child: Column(
children: <Widget>[
new Text(data[index]['title'] == null ? 'not found' : data[index]['title'], style: textStyles['title']),
new Text(data[index]['description'] == null ? 'not found' : data[index]['description'], style: textStyles['disc']),
],
),
),
new Container(
width: 100.0,
padding: EdgeInsets.all(5.0),
child: Column(
children: <Widget>[
new Image.network(data[index]['urlToImage'] == null ? url : data[index]['urlToImage'], fit: BoxFit.fill,),

],
),
)
],
),

),
new Container(
margin: EdgeInsets.all(8.0),
foregroundDecoration: BoxDecoration(border: Border()),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new IconButton(
icon: new Icon(Icons.share),
tooltip: 'Share news',
onPressed: () { setState(() { }); },
),
new IconButton(
icon: new Icon(Icons.bookmark),
tooltip: ' save for later ',
onPressed: () { setState(() { }); },
)
],
),
)

],
),
);
}
) : new WorkSpace(),// DATA LOADER End

),
);
}
}
20 changes: 20 additions & 0 deletions lib/widgets/NewsSort.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NewsSort extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
appBar: AppBar(
title: Text("NewsSort"),
backgroundColor: Colors.blue,
);
return Container(
child: new Center (
child: Text('NewsSort'),
),

);
}
}
9 changes: 1 addition & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,12 @@ packages:
name: flutter_spinkit
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.1.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_webview_plugin:
dependency: "direct main"
description:
name: flutter_webview_plugin
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1+2"
front_end:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit 547d8a3

Please sign in to comment.