Skip to content

Instantly share code, notes, and snippets.

View xsahil03x's full-sized avatar
🤹‍♂️
Working on something awesome

Sahil Kumar xsahil03x

🤹‍♂️
Working on something awesome
View GitHub Profile
class MovieScreen extends StatefulWidget {
@override
_MovieScreenState createState() => _MovieScreenState();
}
class _MovieScreenState extends State<MovieScreen> {
MovieBloc _bloc;
@override
void initState() {
class MovieBloc {
MovieRepository _movieRepository;
StreamController _movieListController;
StreamSink<ApiResponse<List<Movie>>> get movieListSink =>
_movieListController.sink;
Stream<ApiResponse<List<Movie>>> get movieListStream =>
_movieListController.stream;
class MovieRepository {
final String _apiKey = "Paste your api key here";
ApiBaseHelper _helper = ApiBaseHelper();
Future<List<Movie>> fetchMovieList() async {
final response = await _helper.get("movie/popular?api_key=$_apiKey");
return MovieResponse.fromJson(response).results;
}
}
class ApiResponse<T> {
Status status;
T data;
String message;
ApiResponse.loading(this.message) : status = Status.LOADING;
ApiResponse.completed(this.data) : status = Status.COMPLETED;
ApiResponse.error(this.message) : status = Status.ERROR;
@override
class MovieResponse {
int totalResults;
List<Movie> results;
MovieResponse.fromJson(Map<String, dynamic> json) {
totalResults = json['total_results'];
if (json['results'] != null) {
results = new List<Movie>();
json['results'].forEach((v) {
results.add(new Movie.fromJson(v));
class AppException implements Exception {
final _message;
final _prefix;
AppException([this._message, this._prefix]);
String toString() {
return "$_prefix$_message";
}
}
class ApiBaseHelper {
final String _baseUrl = "http://api.themoviedb.org/3/";
Future<dynamic> get(String url) async {
var responseJson;
try {
final response = await http.get(_baseUrl + url);
responseJson = _returnResponse(response);
} on SocketException {
@xsahil03x
xsahil03x / PermissionSwitches.java
Created April 5, 2019 10:29
Databinding with observable fields.
public class PermissionSwitches extends BaseObservable {
private boolean usageAccess;
private boolean drawOverAccess;
private boolean notificationAccess;
@Bindable
public boolean isPermissionsAvailable() {
return isNotificationAccess()
&& isDrawOverAccess()
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final FirebaseAuth _auth = FirebaseAuth.instance;
@override
Widget build(BuildContext context) {
return MaterialApp(
Future<void> _onVerifyButtonClick() async {
showProgressBar(context, "Verifying OTP, Please Wait!");
String otp = _otpController.text.trim();
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: _verificationId,
smsCode: otp,
);
await _auth.signInWithCredential(credential).then((user) {