Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:cryptick/data/crypto_data.dart';
- import 'package:cryptick/modules/crypto_presenter.dart';
- import 'package:shimmer/shimmer.dart';
- import 'dart:async';
- import 'package:path_provider/path_provider.dart';
- import 'dart:io';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => new _HomePageState();
- }
- class MoreInfoScreen extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- centerTitle: true,
- backgroundColor: Colors.black,
- title: new Text("More Info",
- style: new TextStyle(
- fontFamily: 'PlayfairDisplay',
- letterSpacing: 0.8
- )
- ),
- ),
- body: new Center(
- child: new Card(
- child: new Column(
- children: [
- new ListTile(
- title: new Text('Squared Software London',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- subtitle: new Text('Cryp-Tick Exchange'),
- leading: new CircleAvatar(
- radius: 18.5,
- backgroundImage: new NetworkImage('https://instagram.flhr4-2.fna.fbcdn.net/vp/d5dfc743e547f88c553af0b9bdc33ece/5BCDB00D/t51.2885-19/s150x150/34885182_217909492157471_8233391730213257216_n.jpg'),
- )
- ),
- new ListTile(
- subtitle: new Text('Contact us at: squaredsoftwarelondon@gmail.com',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Icon(
- Icons.alternate_email,
- color: Colors.red[500],
- ),
- ),
- new Divider(),
- new ListTile(
- title: new Text('Cryp-Tick Exchange uses the Public Ticker V1 API available from: https://coinmarketcap.com/api/',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
- class SettingsScreen extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- centerTitle: true,
- backgroundColor: Colors.black,
- title: new Text("Settings",
- style: new TextStyle(
- fontFamily: 'PlayfairDisplay',
- letterSpacing: 0.8
- )
- ),
- ),
- body: new Center(
- child: new Column(
- children: [
- new ListTile(
- title: new MaterialButton(
- child: new Text(
- 'Fiat Currencies',
- textAlign: TextAlign.center,
- style: new TextStyle(
- fontSize: 20.0,
- letterSpacing: 0.8,
- fontFamily: 'PlayfairDisplay'
- ),
- ),
- onPressed: (){
- Navigator.push(
- context,
- new MaterialPageRoute(builder: (context) => new CurrencyScreen()),
- );
- }
- ),
- ),
- new Divider(),
- new ListTile(
- title: new MaterialButton(
- child: new Text(
- 'Fill with more options',
- textAlign: TextAlign.center,
- style: new TextStyle(
- fontSize: 20.0,
- letterSpacing: 0.8,
- fontFamily: 'PlayfairDisplay'
- ),
- ),
- onPressed: (){
- Navigator.push(
- context,
- new MaterialPageRoute(builder: (context) => new SettingsScreen()),
- );
- }
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
- class CurrencyScreen extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- centerTitle: true,
- backgroundColor: Colors.black,
- title: new Text("Choose your fiat exchange currency",
- style: new TextStyle(
- fontFamily: 'PlayfairDisplay',
- letterSpacing: 0.8
- )
- ),
- ),
- body: new Center(
- child: new Column(
- children: [
- new ListTile(
- title: new Text('British Pound Sterling',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text('£',
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 30.0)),
- ),
- new Divider(),
- new ListTile(
- title: new Text('United States Dollar',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("US\$",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 15.0)),
- ),
- new Divider(),
- new ListTile(
- title: new Text('Euro',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("€",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 30.0)),
- ),
- new Divider(),
- new ListTile(
- title: new Text('Japanese yen',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("¥",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 30.0)),
- ),
- new Divider(),
- new ListTile(
- title: new Text('Australian Dollar',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("A\$",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0),
- )
- ),
- new Divider(),
- new ListTile(
- title: new Text('Canadian Dollar',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("A\$",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 20.0),
- )
- ),
- new Divider(),
- new ListTile(
- title: new Text('Swiss Franc',
- style: new TextStyle(fontWeight: FontWeight.w500)),
- leading: new Text("CHF",
- style: new TextStyle(fontWeight: FontWeight.w500, fontSize: 15.0),
- )
- ),
- ],
- ),
- ),
- );
- }
- }
- class _HomePageState extends State<HomePage> implements CryptoListViewContract {
- CryptoListPresenter _presenter;
- List<Crypto> _currencies;
- bool _isLoading;
- final List<MaterialColor> _colors = [Colors.blue, Colors.indigo, Colors.red];
- _HomePageState() {
- _presenter = new CryptoListPresenter(this);
- }
- var refreshKey = new GlobalKey<RefreshIndicatorState>();
- @override
- void initState() {
- super.initState();
- _isLoading = true;
- _presenter.loadCurrencies();
- refreshList();
- }
- Future<Null> refreshList() async {
- refreshKey.currentState?.show(atTop: false);
- await new Future.delayed(new Duration(seconds: 1));
- _presenter.loadCurrencies();
- Scaffold.of(context).showSnackBar(
- new SnackBar(
- duration: new Duration(seconds: 3),
- backgroundColor: Colors.black,
- content: new Text(
- 'Refresh available every 60 seconds',
- textAlign: TextAlign.center,
- style: new TextStyle(
- letterSpacing: 0.8,
- fontFamily: 'PlayfairDisplay'
- ),
- ),
- ),
- );
- setState(() {
- });
- return null;
- }
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- appBar: new AppBar(
- centerTitle: true,
- backgroundColor: Colors.black,
- title: new Text("Cryp-Tick Exchange",
- style: new TextStyle(
- fontFamily: 'PlayfairDisplay',
- letterSpacing: 0.8
- )
- ),
- elevation: defaultTargetPlatform == TargetPlatform.iOS ? 0.0 : 5.0,
- ),
- drawer: new Drawer(
- child: new ListView(
- padding: EdgeInsets.zero,
- children: <Widget>[
- new DrawerHeader(
- child: new CircleAvatar(
- child: new Image.asset('images/ctavatar.png'),
- ),
- decoration: new BoxDecoration(
- color: Colors.black,
- ),
- ),
- new MaterialButton(
- child: new Text(
- 'More Info',
- textAlign: TextAlign.center,
- style: new TextStyle(
- fontSize: 20.0,
- letterSpacing: 0.8,
- fontFamily: 'PlayfairDisplay'
- ),
- ),
- onPressed: (){
- Navigator.push(
- context,
- new MaterialPageRoute(builder: (context) => new MoreInfoScreen()),
- );
- }
- ),
- new Divider(),
- new MaterialButton(
- child: new Text(
- 'Settings',
- textAlign: TextAlign.center,
- style: new TextStyle(
- fontSize: 20.0,
- letterSpacing: 0.8,
- fontFamily: 'PlayfairDisplay'
- ),
- ),
- onPressed: (){
- Navigator.push(
- context,
- new MaterialPageRoute(builder: (context) => new SettingsScreen()),
- );
- }
- ),
- ]
- ),
- ),
- body: _isLoading
- ? new Center(
- child: new CircularProgressIndicator(),
- )
- : _cryptoWidget()
- );
- }
- Widget _cryptoWidget() {
- return new Container(
- child: new Column(
- children: <Widget>[
- new Flexible(
- child: new ListView.builder(
- scrollDirection: Axis.horizontal,
- itemBuilder: (BuildContext context, int index) {
- return _listViewFiller();
- }
- ),
- ),
- new Flexible(
- child: new RefreshIndicator(
- key: refreshKey,
- child: new ListView.builder(
- scrollDirection: Axis.horizontal,
- itemCount: _currencies.length,
- itemBuilder: (BuildContext context, int index) {
- final int i = index ~/ 2;
- final Crypto currency = _currencies[i];
- final MaterialColor color = _colors[i % _colors.length];
- if (index.isOdd) {
- return new Divider();
- }
- return _getListItemUi(currency, color);
- },
- ),
- onRefresh:refreshList,
- ),
- )
- ],
- )
- );
- }
- ListTile _getListItemUi(Crypto currency, MaterialColor color) {
- return new ListTile(
- leading: new Image.asset("cryptoiconsWhite/"+currency.symbol.toLowerCase()+"@2x.png"),
- title: new Text(currency.name,
- style: new TextStyle(fontWeight: FontWeight.bold)),
- subtitle:
- _getSubtitleText(currency.price_usd, currency.percent_change_1h),
- isThreeLine: true,
- trailing: new IconButton(
- icon: new Icon(Icons.add),
- onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory();
- String appDocPath = appDocDir.path;
- var myFile = new File('$appDocPath/my_file.txt')
- ..writeAsStringSync('myVar: $_currencies');
- print(myFile.absolute.path);
- }
- ),
- );
- }
- Card _listViewFiller() {
- new BorderRadius.circular(30.0);
- return new Card(
- child: new SizedBox(
- height: 300.0,
- width: 300.0,
- child: new SizedBox(
- child: new Image.network(
- 'https://proxy.duckduckgo.com/iu/?u=http%3A%2F%2Fwww.personaltouchcolorado.com%2Fwp-content%2Fuploads%2F2013%2F01%2FGoodner-Waterfall1-e1362453084645.jpg&f=1'
- ),
- ),
- ),
- );
- }
- Widget _getSubtitleText(String priceUSD, String percentageChange) {
- TextSpan priceTextWidget = new TextSpan(
- text: "\$$priceUSD\n", style: new TextStyle(color: Colors.black));
- String percentageChangeText = "1 hour: $percentageChange%";
- TextSpan percentageChangeTextWidget;
- if (double.parse(percentageChange) > 0) {
- percentageChangeTextWidget = new TextSpan(
- text: percentageChangeText,
- style: new TextStyle(color: Colors.green ));
- } else {
- percentageChangeTextWidget = new TextSpan(
- text: percentageChangeText, style: new TextStyle(color: Colors.red));
- }
- return new RichText(
- text: new TextSpan(
- children: [priceTextWidget, percentageChangeTextWidget]));
- }
- @override
- void onLoadCryptoComplete(List<Crypto> items) {
- // TODO: implement onLoadCryptoComplete
- setState(() {
- _currencies = items;
- _isLoading = false;
- });
- }
- @override
- void onLoadCryptoError() {
- // TODO: implement onLoadCryptoError
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement