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 | |
// NearMeSwiftUI | |
// | |
// Created by Mohammad Azam on 1/10/20. | |
// Copyright © 2020 Mohammad Azam. All rights reserved. | |
// | |
import SwiftUI | |
import MapKit |
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
Positioned( | |
bottom: 0, | |
child: AnimatedContainer( | |
height: _expanded ? 800 : 210, | |
duration: Duration(milliseconds: 500), | |
curve: Curves.easeInOut, | |
child: NewsList( | |
articles: vm.newsArticles, | |
onHeaderTapped: () { | |
setState(() { |
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/view_models/home_page_view_model.dart'; | |
class NewsList extends StatelessWidget { | |
final List<NewsArticleViewModel> articles; | |
final Function onHeaderTapped; | |
final Function(DragUpdateDetails) onDragUpdate; | |
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
Future<void> load() async { | |
final list = await Future.wait([Webservice().getStocks(), Webservice().getTopNews()]); | |
stocks = list.first.map((stock) => StockViewModel(stock: stock)).toList(); // stocks | |
newsArticles = list.last.map((newsArticle) => NewsArticleViewModel(newsArticle: newsArticle)).toList(); // news articles | |
notifyListeners(); | |
} |
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 NewsArticleViewModel { | |
final NewsArticle newsArticle; | |
NewsArticleViewModel({this.newsArticle}); | |
String get title { | |
return newsArticle.title; | |
} |
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 NewsArticle { | |
final String title; | |
final String publication; | |
final String imageURL; | |
NewsArticle({this.title, this.publication, this.imageURL}); | |
factory NewsArticle.fromJson(Map<String, dynamic> json) { |
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
Future<List<NewsArticle>> getTopNews() async { | |
final url = "https://silicon-rhinoceros.glitch.me/top-news"; | |
final response = await http.get(url); | |
if(response.statusCode == 200) { | |
Iterable json = jsonDecode(response.body); | |
return json.map((newsArticle) => NewsArticle.fromJson(newsArticle)).toList(); | |
} else { | |
throw Exception("Error fetching news"); |
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
app.get("/top-news", (req, res) => { | |
let articles = [ | |
{ | |
title: "The Bull Market is Charging into 2020", | |
publication: "THE WALSTREET JOURNAL", | |
imageURL: "https://i.ytimg.com/vi/gtkiRJwSN10/maxresdefault.jpg" | |
}, | |
{ | |
title: "Tencent Groups 10% of Univercal Music", | |
publication: "Bloomberg", |
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 StockListViewModel extends ChangeNotifier { | |
List<StockViewModel> stocks = List<StockViewModel>(); | |
List<StockViewModel> allStocks = List<StockViewModel>(); | |
Future<void> fetchStocks() async { | |
... | |
} | |
void search(String searchTerm) { |
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/view_models/stock_list_view_model.dart'; | |
class StockList extends StatelessWidget { | |
final List<StockViewModel> stocks; | |
StockList({this.stocks}); |