Robo-advisory-dart/lib/screens/history/history.dart

113 lines
4 KiB
Dart

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<HistoryScreen> {
bool loadingData = true;
List<Transaction> transactionData = [];
void initState() {
TransactionProvider transactionProvider =
Provider.of<TransactionProvider>(context, listen: false);
transactionProvider.loadTransactions().then((value) {
Timer(Duration(seconds: 3), () {
setState(() {
loadingData = false;
transactionData = value;
Provider.of<TransactionProvider>(context, listen: false)
.setTransactionsList(transactionData);
});
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
List<Transaction> transactionList =
Provider.of<TransactionProvider>(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<String>(
isExpanded: true,
items: [
DropdownMenuItem<String>(
value: null,
child: Text('All'),
),
...Provider.of<UserProvider>(context, listen: true)
.categories
.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
})
],
hint: new Text("Select Category"),
value: Provider.of<TransactionProvider>(context,
listen: true)
.selectedCategory,
onChanged: (String? newValue) {
Provider.of<TransactionProvider>(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'),
),
),
],
),
),
);
}
}