import 'package:InvenTree/user_profile.dart'; import 'package:InvenTree/widget/starred_parts.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'file:///C:/inventree-app/lib/l10.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/api.dart'; import 'package:InvenTree/settings/login.dart'; import 'package:InvenTree/widget/category_display.dart'; import 'package:InvenTree/widget/company_list.dart'; import 'package:InvenTree/widget/location_display.dart'; import 'package:InvenTree/widget/search.dart'; import 'package:InvenTree/widget/spinner.dart'; import 'package:InvenTree/widget/drawer.dart'; class InvenTreeHomePage extends StatefulWidget { InvenTreeHomePage({Key key}) : super(key: key); @override _InvenTreeHomePageState createState() => _InvenTreeHomePageState(); } class _InvenTreeHomePageState extends State { final GlobalKey<_InvenTreeHomePageState> _homeKey = GlobalKey<_InvenTreeHomePageState>(); _InvenTreeHomePageState() : super() { // Initially load the profile and attempt server connection _loadProfile(); } // Selected user profile UserProfile _profile; BuildContext _context; void _searchParts() { if (!InvenTreeAPI().checkConnection(context)) return; showSearch( context: context, delegate: PartSearchDelegate(context) ); } void _searchStock() { if (!InvenTreeAPI().checkConnection(context)) return; showSearch( context: context, delegate: StockSearchDelegate(context) ); } void _scan(BuildContext context) { if (!InvenTreeAPI().checkConnection(context)) return; scanQrCode(context); } void _parts(BuildContext context) { if (!InvenTreeAPI().checkConnection(context)) return; Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); } void _stock(BuildContext context) { if (!InvenTreeAPI().checkConnection(context)) return; Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null))); } void _suppliers() { if (!InvenTreeAPI().checkConnection(context)) return; Navigator.push(context, MaterialPageRoute(builder: (context) => SupplierListWidget())); } void _manufacturers() { if (!InvenTreeAPI().checkConnection(context)) return; Navigator.push(context, MaterialPageRoute(builder: (context) => ManufacturerListWidget())); } void _customers() { if (!InvenTreeAPI().checkConnection(context)) return; Navigator.push(context, MaterialPageRoute(builder: (context) => CustomerListWidget())); } void _selectProfile() { Navigator.push( context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget()) ).then((context) { // Once we return _loadProfile(); }); } void _loadProfile() async { _profile = await UserProfileDBManager().getSelectedProfile(); // A valid profile was loaded! if (_profile != null) { if (!InvenTreeAPI().isConnected() && !InvenTreeAPI().isConnecting()) { // Attempt server connection InvenTreeAPI().connectToServer(_homeKey.currentContext).then((result) { setState(() {}); }); } } setState(() {}); } ListTile _serverTile() { // No profile selected // Tap to select / create a profile if (_profile == null) { return ListTile( title: Text(L10().profileNotSelected), subtitle: Text(L10().profileTapToCreate), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( FontAwesomeIcons.user, color: Color.fromRGBO(250, 50, 50, 1), ), onTap: () { _selectProfile(); }, ); } // Profile is selected ... if (InvenTreeAPI().isConnecting()) { return ListTile( title: Text(L10().serverConnecting), subtitle: Text("${InvenTreeAPI().baseUrl}"), leading: FaIcon(FontAwesomeIcons.server), trailing: Spinner( icon: FontAwesomeIcons.spinner, color: Color.fromRGBO(50, 50, 250, 1), ), onTap: () { _selectProfile(); } ); } else if (InvenTreeAPI().isConnected()) { return ListTile( title: Text(L10().serverConnected), subtitle: Text("${InvenTreeAPI().baseUrl}"), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( FontAwesomeIcons.checkCircle, color: Color.fromRGBO(50, 250, 50, 1) ), onTap: () { _selectProfile(); }, ); } else { return ListTile( title: Text(L10().serverCouldNotConnect), subtitle: Text("${_profile.server}"), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( FontAwesomeIcons.timesCircle, color: Color.fromRGBO(250, 50, 50, 1), ), onTap: () { _selectProfile(); }, ); } } @override Widget build(BuildContext context) { _context = context; // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( key: _homeKey, appBar: AppBar( title: Text(L10().appTitle), actions: [ /* IconButton( icon: FaIcon(FontAwesomeIcons.search), tooltip: L10().search, onPressed: _searchParts, ), */ ], ), drawer: new InvenTreeDrawer(context), body: Center( // Center is a layout widget. It takes a single child and positions it // in the middle of the parent. child: Column( mainAxisAlignment: MainAxisAlignment.center, children: ([ Spacer(), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.barcode), tooltip: L10().scanBarcode, onPressed: () { _scan(context); }, ), Text(L10().scanBarcode), ], ), ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.shapes), tooltip: L10().parts, onPressed: () { _parts(context); }, ), Text(L10().parts), ], ), Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.search), tooltip: L10().searchParts, onPressed: _searchParts, ), Text(L10().searchParts), ], ), // TODO - Re-add starred parts link /* Column( children: [ IconButton( icon: FaIcon(FontAwesomeIcons.solidStar), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => StarredPartWidget())); }, ), Text("Starred Parts"), ] ), */ ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.boxes), tooltip: L10().stock, onPressed: () { _stock(context); }, ), Text(L10().stock), ], ), Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.search), tooltip: L10().searchStock, onPressed: _searchStock, ), Text(L10().searchStock), ], ), ] ), Spacer(), // TODO - Re-add these when the features actually do something.. /* Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.building), tooltip: "Suppliers", onPressed: _suppliers, ), Text("Suppliers"), ], ), Column( children: [ IconButton( icon: FaIcon(FontAwesomeIcons.industry), tooltip: "Manufacturers", onPressed: _manufacturers, ), Text("Manufacturers") ], ), Column( children: [ IconButton( icon: FaIcon(FontAwesomeIcons.userTie), tooltip: "Customers", onPressed: _customers, ), Text("Customers"), ] ) ], ), Spacer(), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.tools), tooltip: "Build", onPressed: _unsupported, ), Text("Build"), ], ), Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.shoppingCart), tooltip: "Order", onPressed: _unsupported, ), Text("Order"), ] ), Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.truck), tooltip: "Ship", onPressed: _unsupported, ), Text("Ship"), ] ) ], ), Spacer(), */ Spacer(), Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: _serverTile(), ), ], ), ]), ), ), ); } }