import 'package:flutter/material.dart'; import 'package:robo_advisory/models/wallet.dart'; import 'package:robo_advisory/screens/dashboard/local_widgets/bottom_navigation.dart'; import 'package:robo_advisory/screens/home/home.dart'; import 'package:robo_advisory/screens/fund_transfer/fund_transfer.dart'; import 'package:robo_advisory/screens/settlement/settlement.dart'; import 'package:robo_advisory/screens/history/history.dart'; import 'package:robo_advisory/widgets/drawer.dart'; import 'package:provider/provider.dart'; import 'package:robo_advisory/providers/wallet_provider.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; // TODO: temp import 'dart:async'; class DashboardScreen extends StatefulWidget { @override _DashboardScreenState createState() => _DashboardScreenState(); } class _DashboardScreenState extends State { final GlobalKey _scaffoldKey = GlobalKey(); void _openEndDrawer() { _scaffoldKey.currentState.openEndDrawer(); } int _selectedIndex = 0; bool loadingData = true; Wallet walletData; void _onItemTapped(int index) { setState(() { _selectedIndex = index; }); } void initState() { WalletProvider walletProvider = Provider.of(context, listen: false); walletProvider.loadWallet().then((value) { if (value.totalAssets != null) { Timer(Duration(seconds: 3), () { setState(() { loadingData = false; walletData = value; }); print(value.totalAssets); }); } }); super.initState(); } @override Widget build(BuildContext context) { var currentTab = [ HomeScreen( toggleDrawer: _openEndDrawer, wallet: walletData, ), FundTransferScreen(), SettlementScreen(), HistoryScreen(), ]; return Scaffold( key: _scaffoldKey, backgroundColor: Colors.white, body: loadingData ? Container( child: Center( child: SpinKitFadingFour( color: Colors.black, size: 100.0, ), ), ) : currentTab[_selectedIndex], endDrawer: AppDrawer(), bottomNavigationBar: BottomNavigation( selectedIndex: _selectedIndex, onItemTapped: _onItemTapped, )); } }