This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
StockListViewModel _vm; | |
@override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:provider/provider.dart'; | |
import 'package:stocks_app_flutter/pages/home_page.dart'; | |
import 'package:stocks_app_flutter/view_models/stock_list_view_model.dart'; | |
void main() => runApp(App()); | |
class App extends StatelessWidget { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:stocks_app_flutter/models/stock.dart'; | |
import 'package:stocks_app_flutter/services/webservice.dart'; | |
class StockListViewModel extends ChangeNotifier { | |
List<StockViewModel> stocks = List<StockViewModel>(); | |
List<StockViewModel> allStocks = List<StockViewModel>(); | |
Future<void> fetchStocks() async { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stock { | |
final String symbol; | |
final String company; | |
final double price; | |
final String change; | |
Stock({this.symbol, this.company, this.price, this.change}); | |
factory Stock.fromJson(Map<String, dynamic> json) { | |
return Stock( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:stocks_app_flutter/models/stock.dart'; | |
import 'package:http/http.dart' as http; | |
class Webservice { | |
Future<List<Stock>> getStocks() async { | |
final url = "https://silicon-rhinoceros.glitch.me/stocks"; | |
final response = await http.get(url); | |
if (response.statusCode == 200) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// init project | |
const express = require("express"); | |
const app = express(); | |
app.get("/stocks", (req, res) => { | |
let stocks = [ | |
{ | |
symbol: "GOOG", | |
description: "Google Innovation Media", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// StockListView.swift | |
// stocks | |
// | |
// Created by Mohammad Azam on 12/22/19. | |
// Copyright © 2019 Mohammad Azam. All rights reserved. | |
// | |
import SwiftUI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// stocks | |
// | |
// Created by Mohammad Azam on 12/22/19. | |
// Copyright © 2019 Mohammad Azam. All rights reserved. | |
// | |
import SwiftUI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
class StockListViewModel: ObservableObject { | |
@Published var searchTerm: String = "" | |
@Published var stocks: [StockViewModel] = [StockViewModel]() | |
func load() { | |
fetchStocks() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct StockViewModel { | |
let stock: Stock | |
var symbol: String { | |
return self.stock.symbol.uppercased() | |
} | |
var description: String { | |
return self.stock.description |