Skip to content

Instantly share code, notes, and snippets.

View bharathraj-e's full-sized avatar
🦊

Bharathraj bharathraj-e

🦊
View GitHub Profile
@bharathraj-e
bharathraj-e / webview_downloader.java
Created January 7, 2020 04:19
webview file download code for android studio
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimeType, long contentLength) {
DownloadManager.Request request = new
DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
@bharathraj-e
bharathraj-e / prefs.dart
Last active February 4, 2023 09:55
flutter shared preferences singleton shortcut for set and get
import 'package:shared_preferences/shared_preferences.dart';
class Prefs {
static SharedPreferences _prefs;
// call this method from iniState() function of mainApp().
static Future<SharedPreferences> init() async {
_prefs = await SharedPreferences.getInstance();
return _prefs;
@bharathraj-e
bharathraj-e / error-reporting.php
Created January 9, 2020 07:13
Turning on-off error reporting in php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
@bharathraj-e
bharathraj-e / json-decode.php
Last active July 13, 2020 05:17
decode json from file_get_contents(); ,with error displaying
function decodeJson($json, $assoc = false)
{
$json = preg_replace('/[\x00-\x1F\x7F]/u', '', $json);
$ret = json_decode($json, $assoc);
if ($error = json_last_error()) {
$errorReference = [
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
JSON_ERROR_SYNTAX => 'Syntax error.',
@bharathraj-e
bharathraj-e / snacky-bar.dart
Created January 11, 2020 04:19
A function to create snackbar in flutter
//final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
snackyBar(String content, GlobalKey<ScaffoldState> _scaffoldKey) {
final snackBar = SnackBar(
content: Text(content),
duration: const Duration(seconds: 2),
backgroundColor: Colors.lightBlue,
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
class ResponsiveExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[350],
appBar: AppBar(
title: Text('Responsive Example'),
centerTitle: true,
),
body: Container(
@bharathraj-e
bharathraj-e / request.dart
Last active September 15, 2020 08:55
Flutter http request simplified
import 'dart:convert';
import 'package:http/http.dart' as http;
const String _host = "https://<....>";
class MyRequest {
final String url;
final Map<String, String> headers = {'Authorization': 'Bearer token'};
@bharathraj-e
bharathraj-e / date_format.dart
Created February 1, 2020 04:51
date picker and date to user readable string
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
Future<DateTime> fetchDate(BuildContext context,
{DateTime initialDate, DateTime last}) async {
DateTime t = await showDatePicker(
context: context,
firstDate: DateTime(DateTime.now().year - 1),
initialDate: initialDate ?? DateTime.now(),
lastDate: last ?? DateTime(DateTime.now().year + 2),
import 'package:permission_handler/permission_handler.dart';
() async {
PermissionStatus p = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.contacts);
if (p == PermissionStatus.disabled) {
// permission got already / success
return true;
}
@bharathraj-e
bharathraj-e / check-request.php
Created March 29, 2020 06:01
Check request and finalize response
<?php
function err($err)
{
$res['state'] = false;
$res['err'] = $err;
echo json_encode($res);
die();
}