Created
December 3, 2019 12:23
-
-
Save MarcosSarges/63a3dfc6d485e1b9508728762d3afe08 to your computer and use it in GitHub Desktop.
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:bloc_pattern/bloc_pattern.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:fluttetube/blocs/videos_bloc.dart'; | |
| import 'package:fluttetube/screens/home_screen.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return BlocProvider( | |
| // isso aqui ta certo? no video ta diferente... | |
| blocs: [Bloc((i) => VideosBloc())], | |
| child: MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: Home(), | |
| )); | |
| } | |
| } | |
| Main | |
| ------------------------------ | |
| // isso aqui é outro arquivo | |
| import 'dart:async'; | |
| import 'package:bloc_pattern/bloc_pattern.dart'; | |
| import 'package:fluttetube/models/video_model.dart'; | |
| import 'package:fluttetube/services/api.dart'; | |
| class VideosBloc extends BlocBase { | |
| Api api; | |
| List<Video> videos; | |
| // expondo a stream--- ta saindo o video | |
| final _videosController = StreamController<List<Video>>(); | |
| Stream get outVideos => _videosController.stream; | |
| //------------------------------------------ | |
| final _searchController = StreamController<String>(); | |
| // expondo o sink --- ta entrando uma pesquisa | |
| Sink get inSearch => _searchController.sink; | |
| VideosBloc() { | |
| api = Api(); | |
| //toda entrada ele pesquisa | |
| _searchController.stream.listen(_search); | |
| } | |
| void _search(String search) async { | |
| print(search); | |
| videos = await api.search(search); | |
| } | |
| @override | |
| void dispose() { | |
| super.dispose(); | |
| _videosController.close(); | |
| _searchController.close(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment