Skip to content

Commit

Permalink
fetch members from contract table
Browse files Browse the repository at this point in the history
  • Loading branch information
7flash committed Dec 21, 2019
1 parent eb6e719 commit 6b203f7
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 163 deletions.
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:flutter/material.dart';
import 'package:seeds/onboarding.dart';
import 'package:seeds/transferAmount.dart';
import 'package:seeds/transferForm.dart';

import './app.dart';

Expand Down
108 changes: 0 additions & 108 deletions lib/members.dart

This file was deleted.

14 changes: 14 additions & 0 deletions lib/progressBar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter/material.dart';

import 'customColors.dart';

class ProgressBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: LinearProgressIndicator(
backgroundColor: CustomColors.Green,
),
);
}
}
162 changes: 112 additions & 50 deletions lib/transfer.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
import 'dart:convert';
import 'package:http/http.dart';

import 'package:flutter/material.dart';
import 'package:seeds/progressBar.dart';

import 'customColors.dart';
import 'transferForm.dart';
import 'members.dart';

class MemberModel {
final String account;
final String nickname;
final String image;

MemberModel({this.account, this.nickname, this.image});

factory MemberModel.fromJson(Map<String, dynamic> json) {
return MemberModel(
account: json["account"],
nickname: json["nickname"],
image: json["image"]);
}
}

class HttpService {
final String membersURL = 'https://api.telos.eosindex.io/v1/chain/get_table_rows';

Future<List<MemberModel>> getMembers() async {
print('get members');

String request =
'{"json":true,"code":"accts.seeds","scope":"accts.seeds","table":"users","table_key":"","lower_bound":null,"upper_bound":null,"index_position":1,"key_type":"i64","limit":"1000","reverse":false,"show_payer":false}';
Map<String, String> headers = {"Content-type": "application/json"};

Response res = await post(membersURL, headers: headers, body: request);

if (res.statusCode == 200) {
Map<String, dynamic> body = jsonDecode(res.body);

List<dynamic> accountsWithProfile = body["rows"].where((dynamic item) {
return item["image"] != "" &&
item["nickname"] != "" &&
item["account"] != "";
}).toList();

List<MemberModel> members =
accountsWithProfile.map((item) => MemberModel.fromJson(item)).toList();

return members;
} else {
print('Cannot fetch members...');

return [];
}
}
}

class Transfer extends StatelessWidget {
final HttpService httpService = HttpService();

@override
Widget build(BuildContext context) {
return SingleChildScrollView(
Expand Down Expand Up @@ -35,21 +88,21 @@ class Transfer extends StatelessWidget {
),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
),
child: ListTile(
leading: Container(
width: 42,
child: Icon(
Icons.star_half,
color: CustomColors.Green,
),
),
title: Text("Activity Rating: 30/100"),
subtitle: Text("Send transactions to increase your activity"),
decoration: BoxDecoration(
color: Colors.white,
),
child: ListTile(
leading: Container(
width: 42,
child: Icon(
Icons.star_half,
color: CustomColors.Green,
),
),
title: Text("Activity Rating: 30/100"),
subtitle: Text("Send transactions to increase your activity"),
),
),
// _usersTitle(),
SizedBox(height: 5),
_usersList(context),
Expand All @@ -73,42 +126,51 @@ class Transfer extends StatelessWidget {
}

Widget _usersList(context) {
return ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemCount: members.length,
itemBuilder: (ctx, index) {
final user = members[index];

return ListTile(
leading: Container(
width: 60,
height: 60,
child: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: AssetImage(user["avatar"]),
),
),
title: Text(
user["fullName"],
style: TextStyle(fontFamily: "worksans"),
),
subtitle: Text(
user["accountName"],
style: TextStyle(fontFamily: "worksans"),
),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TransferForm(
user["fullName"],
user["accountName"],
user["avatar"],
),
),
);
},
);
return FutureBuilder(
future: httpService.getMembers(),
builder: (BuildContext context, AsyncSnapshot<List<MemberModel>> snapshot) {
if (snapshot.hasData) {
final List<MemberModel> members = snapshot.data;
return ListView.builder(
shrinkWrap: true,
physics: ClampingScrollPhysics(),
itemCount: members.length,
itemBuilder: (ctx, index) {
final user = members[index];

return ListTile(
leading: Container(
width: 60,
height: 60,
child: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: NetworkImage(user.image),
),
),
title: Text(
user.nickname,
style: TextStyle(fontFamily: "worksans"),
),
subtitle: Text(
user.account,
style: TextStyle(fontFamily: "worksans"),
),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => TransferForm(
user.nickname,
user.account,
user.image,
),
),
);
},
);
});
} else {
return ProgressBar();
}
});
}
}
15 changes: 15 additions & 0 deletions lib/transferAmount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,27 @@ class _TransferAmountState extends State<TransferAmount> {
fit: FlexFit.loose,
flex: 3,
child: TextField(
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
showCursor: false,
enableInteractiveSelection: false,
autofocus: true,
controller: amountController,
keyboardType: TextInputType.numberWithOptions(
signed: false,
decimal: true,
),
decoration: InputDecoration(
prefixIcon: Padding(
padding: EdgeInsetsDirectional.only(
top: 13, start: 25),
child: Text(
'\$',
style: TextStyle(fontSize: 20),
),
),
prefixStyle: TextStyle(
fontFamily: "vistolsans", fontSize: 25),
border: InputBorder.none,
),
style: TextStyle(
Expand Down
6 changes: 3 additions & 3 deletions lib/transferForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class _TransferFormState extends State<TransferForm>
),
body: SingleChildScrollView(
child: Container(
//width: MediaQuery.of(context).size.width * 1,
width: MediaQuery.of(context).size.width * 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -240,7 +240,7 @@ class _TransferFormState extends State<TransferForm>
height: 150,
child: CircleAvatar(
backgroundColor: Colors.transparent,
backgroundImage: AssetImage(widget.avatar),
backgroundImage: NetworkImage(widget.avatar),
),
),
SizedBox(height: 15),
Expand Down Expand Up @@ -348,7 +348,7 @@ class _TransferFormState extends State<TransferForm>
Opacity(
opacity: this.validAmount ? 1.0 : 0.0,
child: SizedBox(
// width: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
height: 40,
child: FlatButton(
color: CustomColors.Green,
Expand Down

0 comments on commit 6b203f7

Please sign in to comment.