content: import 'dart:async';
  import '../resources/repository.dart';
  import '../models/symbol_model.dart';
  import '../models/chart_model.dart';
  
  class IexBloc {
    final _repository = Repository();
  
    SymbolModel activeSymbol;
  
    final StreamController<List<SymbolModel>> _symbols = StreamController();
    final StreamController<ChartModel> _chart = StreamController();
  
    Stream<List<SymbolModel>> get symbols => _symbols.stream;
    Stream<ChartModel> get chart => _chart.stream;
  
    requestSymbols() async {
      List<SymbolModel> symbolList = [];
      try {
        symbolList = await _repository.iexApiSymbols();
      } catch (e) {
        // Couldn't find symbols.
        print('Could\'t find symbols: $e');
      }
      _symbols.sink.add(symbolList);
    }
  
    requestChart(SymbolModel symbol) async {
      ChartModel chart = await _repository.iexApiChart(symbol);
      _chart.sink.add(chart);
      activeSymbol = symbol;
    }
  
    setSymbols(List<String> symbols) async {
      await _repository.sharedPreferencesProvider.setSymbols(symbols: symbols);
    }
  
    dispose() {
      _symbols.close();
      _chart.close();
    }
  }
  