Skip to content

Commit

Permalink
Merge pull request #13 from imranhashmi/listview
Browse files Browse the repository at this point in the history
#8 #9 #10 also added floating action button
  • Loading branch information
imranhashmi authored Mar 27, 2018
2 parents cc1d7a1 + b219545 commit 56bfc50
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 16 deletions.
15 changes: 15 additions & 0 deletions lib/datamodel/manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Manager {
final String name;
final String description;

Manager(this.name, this.description) {
if (name == null) {
throw new ArgumentError("name of Manager cannot be null. "
"Received: '$name'");
}
if (description == null) {
throw new ArgumentError("description of Manager cannot be null. "
"Received: '$description'");
}
}
}
15 changes: 15 additions & 0 deletions lib/datamodel/store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Store {
final String name;
final String description;

Store(this.name, this.description) {
if (name == null) {
throw new ArgumentError("name of Store cannot be null. "
"Received: '$name'");
}
if (description == null) {
throw new ArgumentError("description of Store cannot be null. "
"Received: '$description'");
}
}
}
15 changes: 15 additions & 0 deletions lib/datamodel/survey.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Survey {
final String name;
final String description;

Survey(this.name, this.description) {
if (name == null) {
throw new ArgumentError("name of Survey cannot be null. "
"Received: '$name'");
}
if (description == null) {
throw new ArgumentError("description of Survey cannot be null. "
"Received: '$description'");
}
}
}
2 changes: 1 addition & 1 deletion lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LoginPageState extends State<LoginPage>
}

void _loadHomePage(){
Navigator.of(context).push( new MaterialPageRoute<Null>(
Navigator.of(context).push( new MaterialPageRoute(
builder: (BuildContext context) {
return new HomePage();
}
Expand Down
77 changes: 72 additions & 5 deletions lib/pages/managers_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
import 'package:flutter/material.dart';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import 'package:dukandaar/datamodel/manager.dart';

class ManagersPageState extends State<ManagersPage> {
var _stores = <Manager>[];

final _biggerFont = const TextStyle(fontSize: 18.0);

@override
void initState() {
super.initState();

// NOT USED for now
//_loadData();
}

class ManagersPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Center(
child: new Text("Managers"),
return new Scaffold (
floatingActionButton: new FloatingActionButton(
onPressed: _addData,
tooltip: 'Add',
child: new Icon(Icons.add)
),
body: new ListView.builder(
itemCount: _stores.length * 2,
itemBuilder: (BuildContext context, int position) {
if (position.isOdd) return new Divider();

final index = position ~/ 2;

return _buildRow(index);
}
),
);
}

Widget _buildRow(int i) {
return new Padding(
padding: const EdgeInsets.all(16.0),
child: new ListTile(
title: new Text(_stores[i].name, style: _biggerFont),
subtitle: new Text(_stores[i].description, style: _biggerFont),
)
);
}

_addData(){
setState((){
// add new store here,
final member = new Manager("dummy" + "${_stores.length}","description");
_stores.add(member);
});
}

// NOT USED for now
_loadData() async {
String dataURL = "https://api.github.com/orgs/raywenderlich/members";
http.Response response = await http.get(dataURL);
setState(() {
final membersJSON = JSON.decode(response.body);

for (var memberJSON in membersJSON) {
final member = new Manager(memberJSON["login"], memberJSON["avatar_url"]);
_stores.add(member);
}
});
}
}

class ManagersPage extends StatefulWidget {
@override
createState() => new ManagersPageState();
}
77 changes: 72 additions & 5 deletions lib/pages/stores_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
import 'package:flutter/material.dart';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import 'package:dukandaar/datamodel/store.dart';

class StoresPageState extends State<StoresPage> {
var _stores = <Store>[];

final _biggerFont = const TextStyle(fontSize: 18.0);

@override
void initState() {
super.initState();

// NOT USED for now
//_loadData();
}

class StoresPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Center(
child: new Text("Stores"),
return new Scaffold (
floatingActionButton: new FloatingActionButton(
onPressed: _addData,
tooltip: 'Add',
child: new Icon(Icons.add)
),
body: new ListView.builder(
itemCount: _stores.length * 2,
itemBuilder: (BuildContext context, int position) {
if (position.isOdd) return new Divider();

final index = position ~/ 2;

return _buildRow(index);
}
),
);
}

Widget _buildRow(int i) {
return new Padding(
padding: const EdgeInsets.all(16.0),
child: new ListTile(
title: new Text(_stores[i].name, style: _biggerFont),
subtitle: new Text(_stores[i].description, style: _biggerFont),
)
);
}

_addData(){
setState((){
// add new store here,
final member = new Store("dummy" + "${_stores.length}","description");
_stores.add(member);
});
}

// NOT USED for now
_loadData() async {
String dataURL = "https://api.github.com/orgs/raywenderlich/members";
http.Response response = await http.get(dataURL);
setState(() {
final membersJSON = JSON.decode(response.body);

for (var memberJSON in membersJSON) {
final member = new Store(memberJSON["login"], memberJSON["avatar_url"]);
_stores.add(member);
}
});
}
}

class StoresPage extends StatefulWidget {
@override
createState() => new StoresPageState();
}
77 changes: 72 additions & 5 deletions lib/pages/surveys_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@
import 'package:flutter/material.dart';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

import 'package:dukandaar/datamodel/survey.dart';

class SurveysPageState extends State<SurveysPage> {
var _stores = <Survey>[];

final _biggerFont = const TextStyle(fontSize: 18.0);

@override
void initState() {
super.initState();

// NOT USED for now
//_loadData();
}

class SurveysPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Center(
child: new Text("Surveys"),
return new Scaffold (
floatingActionButton: new FloatingActionButton(
onPressed: _addData,
tooltip: 'Add',
child: new Icon(Icons.add)
),
body: new ListView.builder(
itemCount: _stores.length * 2,
itemBuilder: (BuildContext context, int position) {
if (position.isOdd) return new Divider();

final index = position ~/ 2;

return _buildRow(index);
}
),
);
}

Widget _buildRow(int i) {
return new Padding(
padding: const EdgeInsets.all(16.0),
child: new ListTile(
title: new Text(_stores[i].name, style: _biggerFont),
subtitle: new Text(_stores[i].description, style: _biggerFont),
)
);
}

_addData(){
setState((){
// add new store here,
final member = new Survey("dummy" + "${_stores.length}","description");
_stores.add(member);
});
}

// NOT USED for now
_loadData() async {
String dataURL = "https://api.github.com/orgs/raywenderlich/members";
http.Response response = await http.get(dataURL);
setState(() {
final membersJSON = JSON.decode(response.body);

for (var memberJSON in membersJSON) {
final member = new Survey(memberJSON["login"], memberJSON["avatar_url"]);
_stores.add(member);
}
});
}
}

class SurveysPage extends StatefulWidget {
@override
createState() => new SurveysPageState();
}

0 comments on commit 56bfc50

Please sign in to comment.