import 'package:flutter/material.dart'; import 'package:robo_advisory/providers/user_provider.dart'; import 'package:robo_advisory/theme/theme.dart'; import 'package:provider/provider.dart'; import 'package:robo_advisory/models/transaction.dart'; import 'package:robo_advisory/providers/transaction_provider.dart'; import 'package:robo_advisory/screens/history/local_widgets/transaction_list_tile.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; // TODO: temp import 'dart:async'; class HistoryScreen extends StatefulWidget { @override _HistoryScreenState createState() => _HistoryScreenState(); } class _HistoryScreenState extends State { bool loadingData = true; List transactionData = []; void initState() { TransactionProvider transactionProvider = Provider.of(context, listen: false); transactionProvider.loadTransactions().then((value) { Timer(Duration(seconds: 3), () { setState(() { loadingData = false; transactionData = value; Provider.of(context, listen: false) .setTransactionsList(transactionData); }); }); }); super.initState(); } @override Widget build(BuildContext context) { List transactionList = Provider.of(context, listen: true).transactionList; return SafeArea( child: loadingData ? Container( child: Center( child: SpinKitFadingFour( color: Colors.black, size: 100.0, ), ), ) : Padding( padding: AppTheme.padding, child: Column( children: [ Column( children: [ DropdownButton( isExpanded: true, items: Provider.of(context, listen: true) .categories .map((String value) { return DropdownMenuItem( value: value, child: Text(value), ); }).toList(), hint: new Text("Select Category"), value: Provider.of(context, listen: true) .selectedCategory ?? 'All', onChanged: (String? newValue) { Provider.of(context, listen: false) .setSelectedCategory(newValue); }, ) ], ), SizedBox( height: 20.0, ), Expanded( child: transactionList.length != 0 ? SingleChildScrollView( child: ListView.builder( scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: transactionList.length, itemBuilder: (context, index) { return TransactionListTile( transactionObject: transactionList[index], ); }, ), ) : Center( child: Text('No Record Found'), ), ), ], ), ), ); } }