1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import 'dart:async';
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- import 'package:rxdart/rxdart.dart';
- import 'package:empty/models/album.dart';
- import 'package:empty/models/bbs.dart';
- import 'package:empty/constants.dart';
- class AlbumBloc {
- final _albumSubject = BehaviorSubject<Album>();
- final _albumGuide = BehaviorSubject<Album>();
- final _bbsList = BehaviorSubject<Bbs>();
- Future<Bbs> getData(String type,String page, String size) async {
- var response = await http.get(
- kConfig['bbs'] + type + "?page=" + page + "&size=" + size,
- headers: {'Content-Type':'application/json','x-aliot-token':kEmptyToken},
- );
- if (response.statusCode == 200) {
- Bbs result = Bbs.fromJson( json.decode(response.body) );
- return result;
- } else {
- print('Request failed with status: ${response.statusCode}.');
- }
- }
- Future<Album> fetchData(String type, String section) async {
- var response = await http.post(
- kConfig['list'],
- body: jsonEncode({'type':type,'section':section,'rcmd':'','size':20,'page':1}),
- headers: {'Content-Type':'application/json','x-aliot-token':kEmptyToken},
- );
- //print(kUserInfo['emptyToken']);
- if (response.statusCode == 200) {
- // print('album : ' + response.body);
- Album result = Album.fromJson( json.decode(response.body) );
- return result;
- } else {
- print('Request failed with status: ${response.statusCode}.');
- }
- }
- void fetch(String type, String section) async {
- var albumResult = await fetchData(type,section);
- _albumSubject.add(albumResult);
- }
- void guide(String type, String section) async {
- var albumResult = await fetchData(type,section);
- _albumGuide.add(albumResult);
- }
- void bbs(String type,String page, String size) async {
- var albumResult = await getData(type,page,size);
- _bbsList.add(albumResult);
- }
- Stream<Album> get albumResult => _albumSubject.stream;
- Stream<Album> get albumGuide => _albumGuide.stream;
- Stream<Bbs> get bbsList => _bbsList.stream;
- }
|