Skip to content

Instantly share code, notes, and snippets.

View achinverma's full-sized avatar
🎯
Focusing

Achin verma achinverma

🎯
Focusing
  • India
View GitHub Profile
class HomeScreen extends StatefulWidget {
HomeScreen();
@override
_HomeScreenState createState() {
return _HomeScreenState();
}
}
class _HomeScreenState extends State<HomeScreen> {
enum PostBlocAction {FetchPosts}
class PostBloc{
//This StreamController is used to update the state of widgets
PublishSubject<PostResponse> _stateStreamController = new PublishSubject();
StreamSink<PostResponse> get _postSink => _stateStreamController.sink;
Stream<PostResponse> get postStream => _stateStreamController.stream;
//user input event StreamController
static Future<FacebookModel> getFbUserData(String fbtoken) async {
//String url1 = "https://graph.facebook.com/${user_id}?fields=name,first_name,last_name,email,&access_token=${fbtoken}";
String url =
'https://graph.facebook.com/v8.0/me?fields=name,first_name,last_name,email&access_token=${fbtoken}';
var request = new http.MultipartRequest("GET", Uri.parse(url));
try {
final response = await request.send().timeout(Duration(seconds: timeout));
final respStr = await response.stream.bytesToString();
// To parse this JSON data, do
//
// final postResponse = postResponseFromJson(jsonString);
import 'dart:convert';
PostResponse postResponseFromJson(String str) => PostResponse.fromJson(json.decode(str));
String postResponseToJson(PostResponse data) => json.encode(data.toJson());
import 'dart:convert';
StoreData storeDataFromJson(String str) => StoreData.fromJson(json.decode(str));
String storeDataToJson(StoreData data) => json.encode(data.toJson());
class StoreData {
bool success;
Store store;
{
"success": true,
"store": {
"id": "1",
"store_name": "Restro App",
"location": "1906 Van Ness Ave",
"city": "San Francisco",
"state": "California",
"country": "United States",
"timezone": "America/Adak",
@achinverma
achinverma / typface
Last active September 20, 2018 07:52
//Why don't you keep the created typface object in memory so that you don't create every time the text view is getting created.
//Following is a sample class that creates and cache the typeface object:
public class TypeFaceProvider {
public static final String TYPEFACE_FOLDER = "fonts";
public static final String TYPEFACE_EXTENSION = ".ttf";
private static Hashtable<String, Typeface> sTypeFaces = new Hashtable<String, Typeface>(
@achinverma
achinverma / AndroidPermissions.java
Created September 20, 2018 04:57
Android Permissions
// called in a standard activity, use ContextCompat.checkSelfPermission for AppCompActivity
int permissionCheck = checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR);
if (!permissionCheck == PackageManager.PERMISSION_GRANTED) {
// User may have declined earlier, ask Android if we should show him a reason
if (shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.WRITE_CALENDAR)) {
// show an explanation to the user
// Good practise: don't block thread after the user sees the explanation, try again to request the permission.
} else {
// request the permission.
public class PolarChartActivity extends AppCompatActivity {
private ChartsPolar polar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chart_common);
AnyChartView anyChartView = findViewById(R.id.any_chart_view);
@achinverma
achinverma / android_shortcut.java
Created January 7, 2017 05:10 — forked from zakelfassi/android_shortcut.java
Create android app shortcut programatically
// Note that a shortcut is created automagically if the app is installed via Play store.
// Change "APP_NAME" by your app name. *MrObvious*
/*Manifest file - add this */
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
/* MainActivity.java */
public class MainActivity ... {
...
private SharedPreferences appSettings;