Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //your Address Class
- class AddressDetails {
- String? address;
- String? balance;
- String? coinName;
- AddressDetails({
- this.address,
- this.balance,
- this.coinName,
- });
- AddressDetails.fromJson(Map<String, dynamic> json) {
- address = json['address'];
- balance = json['balance'];
- coinName = json['coin_name'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = <String, dynamic>{};
- data['address'] = address;
- data['balance'] = balance;
- data['coin_name'] = coinName;
- return data;
- }
- }
- //your transaction class
- class TransactionDetails {
- String? avatar;
- String? name;
- String? date;
- String? amount;
- TransactionDetails({
- this.avatar,
- this.name,
- this.date,
- this.amount,
- });
- TransactionDetails.fromJson(Map<String, dynamic> json) {
- avatar = json['avatar'];
- name = json['name'];
- date = json['date'];
- amount = json['amount'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = <String, dynamic>{};
- data['avatar'] = avatar;
- data['name'] = name;
- data['date'] = date;
- data['amount'] = amount;
- return data;
- }
- }
- //your Addrees API function
- Future<List<AddressDetails>> getAddressData() async {
- final response = await http.get(
- Uri.parse(
- 'https://brotherlike-navies.000webhostapp.com/address/addr.php',
- ),
- );
- if (response.statusCode == 200) {
- final List result = json.decode(response.body);
- return result.map((e) => AddressDetails.fromJson(e)).toList();
- } else {
- throw Exception('Failed to load data');
- }
- }
- //your Transaction API
- Future<List<TransactionDetails>> getTransactionData() async {
- final response = await http.get(Uri.parse(
- 'https://brotherlike-navies.000webhostapp.com/people/people.php'));
- if (response.statusCode == 200) {
- final List result = json.decode(response.body);
- return result.map((e) => TransactionDetails.fromJson(e)).toList();
- } else {
- throw Exception('Failed to load data');
- }
- }
- //If you want only Transaction List Scroll then use below widget
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- width: double.infinity,
- height: 200,
- child: FutureBuilder<List<AddressDetails>>(
- future: getAddressData(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ListView.builder(
- scrollDirection: Axis.horizontal,
- shrinkWrap: true,
- itemCount: snapshot.data!.length,
- itemBuilder: (context, index) {
- return Container(
- padding: const EdgeInsets.all(15),
- margin: const EdgeInsets.all(15),
- width: 319,
- height: 100,
- decoration: BoxDecoration(
- boxShadow: [
- BoxShadow(
- color: const Color.fromARGB(255, 233, 230, 230)
- .withOpacity(0.8),
- spreadRadius: 5,
- blurRadius: 3,
- offset: const Offset(
- 0, 7), // changes position of shadow
- ),
- ],
- color: Colors.green,
- borderRadius: BorderRadius.circular(9)),
- alignment: Alignment.center,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- const Text(
- 'Account Balance',
- style: TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- const SizedBox(
- height: 20,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- snapshot.data![index].balance.toString(),
- style: const TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- const SizedBox(
- width: 5,
- ),
- Text(
- snapshot.data![index].coinName.toString(),
- style: const TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- ],
- ),
- const SizedBox(
- height: 30,
- ),
- Text(
- snapshot.data![index].address.toString(),
- style: const TextStyle(
- fontSize: 15,
- color: Colors.white,
- fontWeight: FontWeight.w600,
- ),
- ),
- ],
- ),
- );
- },
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const Center(child: CircularProgressIndicator());
- },
- ),
- ),
- const Padding(
- padding: EdgeInsets.all(15),
- child: Text(
- "Recent Transactions",
- style: TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.bold,
- color: Colors.green),
- ),
- ),
- Expanded(
- child: Center(
- child: FutureBuilder<List<TransactionDetails>>(
- future: getTransactionData(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ListView.builder(
- // physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- itemCount: snapshot.data!.length,
- itemBuilder: (context, index) {
- return ListTile(
- leading: CircleAvatar(
- child: Image.network(
- snapshot.data![index].avatar.toString()),
- ),
- title: Text(snapshot.data![index].name.toString()),
- trailing:
- Text(snapshot.data![index].amount.toString()),
- subtitle: Text(snapshot.data![index].date.toString()),
- );
- },
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const CircularProgressIndicator();
- },
- ),
- ),
- ),
- ],
- ),
- //If you want your whole widget to scroll then used below code
- SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- width: double.infinity,
- height: 200,
- child: FutureBuilder<List<AddressDetails>>(
- future: getAddressData(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ListView.builder(
- scrollDirection: Axis.horizontal,
- shrinkWrap: true,
- itemCount: snapshot.data!.length,
- itemBuilder: (context, index) {
- return Container(
- padding: const EdgeInsets.all(15),
- margin: const EdgeInsets.all(15),
- width: 319,
- height: 100,
- decoration: BoxDecoration(
- boxShadow: [
- BoxShadow(
- color:
- const Color.fromARGB(255, 233, 230, 230)
- .withOpacity(0.8),
- spreadRadius: 5,
- blurRadius: 3,
- offset: const Offset(
- 0, 7), // changes position of shadow
- ),
- ],
- color: Colors.green,
- borderRadius: BorderRadius.circular(9)),
- alignment: Alignment.center,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: [
- const Text(
- 'Account Balance',
- style: TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- const SizedBox(
- height: 20,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- snapshot.data![index].balance.toString(),
- style: const TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- const SizedBox(
- width: 5,
- ),
- Text(
- snapshot.data![index].coinName.toString(),
- style: const TextStyle(
- fontSize: 20,
- color: Colors.white,
- fontWeight: FontWeight.bold),
- ),
- ],
- ),
- const SizedBox(
- height: 30,
- ),
- Text(
- snapshot.data![index].address.toString(),
- style: const TextStyle(
- fontSize: 15,
- color: Colors.white,
- fontWeight: FontWeight.w600,
- ),
- ),
- ],
- ),
- );
- },
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const Center(child: CircularProgressIndicator());
- },
- ),
- ),
- const Padding(
- padding: EdgeInsets.all(15),
- child: Text(
- "Recent Transactions",
- style: TextStyle(
- fontSize: 14,
- fontWeight: FontWeight.bold,
- color: Colors.green),
- ),
- ),
- Center(
- child: FutureBuilder<List<TransactionDetails>>(
- future: getTransactionData(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ListView.builder(
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- itemCount: snapshot.data!.length,
- itemBuilder: (context, index) {
- return ListTile(
- leading: CircleAvatar(
- child: Image.network(
- snapshot.data![index].avatar.toString()),
- ),
- title: Text(snapshot.data![index].name.toString()),
- trailing:
- Text(snapshot.data![index].amount.toString()),
- subtitle: Text(snapshot.data![index].date.toString()),
- );
- },
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const CircularProgressIndicator();
- },
- ),
- ),
- ],
- ),
- ),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement