Skip to content

Instantly share code, notes, and snippets.

View rohankandwal's full-sized avatar

Rohan Kandwal rohankandwal

  • Bengaluru, Karnataka, India
View GitHub Profile
@rohankandwal
rohankandwal / main.dart
Created April 29, 2023 20:59
File Upload using WebView on Android
/// Read details on https://theprogrammingway.com/flutter-file-upload-using-webview-on-android/
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
void main() {
runApp(const MyApp());
@rohankandwal
rohankandwal / analysis_options.yaml
Created March 10, 2022 09:40 — forked from crizant/analysis_options.yaml
Flutter linting rules
analyzer:
errors:
# treat missing required parameters as a warning (not a hint)
missing_required_param: warning
# treat missing returns as a warning (not a hint)
missing_return: warning
linter:
rules:
- always_declare_return_types
@rohankandwal
rohankandwal / Flutter: Webview loading URL
Last active November 28, 2019 05:08
Loading a url into the webview
final _webViewPlugin = FlutterWebviewPlugin();
@override
Widget build(BuildContext context) {
return WillPopScope(
child: WebviewScaffold(
url: "https://www.google.com",
withZoom: false,
withLocalStorage: true,
withJavascript: true,
@rohankandwal
rohankandwal / Flutter Image as ListView Separator
Created November 27, 2019 11:11
Showing widgets between ListView items in Flutter
@override
Widget build(BuildContext context) {
return ListView.separated(
padding: EdgeInsets.only(top: 8),
separatorBuilder: (context, index) => Icon(Icons.add),
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(list[index].title),
leading: Image.network(list[index].image_url),
subtitle: Text(list[index].subtitle),
@rohankandwal
rohankandwal / Flutter Seperated ListView
Created November 27, 2019 11:05
Adding divider to Flutter's ListView using a Separator
@override
Widget build(BuildContext context) {
return ListView.separated(
padding: EdgeInsets.only(top: 8),
separatorBuilder: (context, index) => Divider(
height: 2,
color: Colors.red,
),
itemBuilder: (BuildContext context, int index) {
return ListTile(
@rohankandwal
rohankandwal / Flutter ListView
Created November 27, 2019 10:48
Basic Flutter ListView implementation
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, index) {
return ListTile(
title: Text(list[index].title),
leading: Image.network(list[index].image_url),
subtitle: Text(list[index].subtitle),
);
},
@rohankandwal
rohankandwal / RxSchedulersOverrideRule.java
Created May 20, 2018 11:37
RxSchedulersOverrideRule - subscriptions always subscribeOn and observeOn Schedulers.trampoline().
package com.itcse.beerrecepies;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.util.concurrent.Callable;
import io.reactivex.Scheduler;
import io.reactivex.android.plugins.RxAndroidPlugins;
@rohankandwal
rohankandwal / AppModule.java
Created May 10, 2018 11:02
AppModule - Used to inject fragments, service, activities with other modules
@Module(includes = {
AndroidInjectionModule.class, RepositoryModule.class,
MySharedPreferencesModule.class
ViewModelModule.class, LocalRepositoryModule.class, MQTTModule.class
})
abstract class AppModule {
/*
* Singleton annotation isn't necessary since Application instance is unique but is here for
* convention. In general, providing Activity, Fragment, BroadcastReceiver, etc does not require
* them to be scoped since they are the components being injected and their instance is unique.
@rohankandwal
rohankandwal / ViewModelModule.java
Created May 10, 2018 10:59
ViewModelModule - Module to bind your ViewModels. We also bind our custom ViewModelFactory here.
@Module
public abstract class ViewModelModule {
@Binds
@IntoMap
@ViewModelKey(SplashScreenViewModel.class)
abstract ViewModel bindSplashScreenViewModel(final SplashScreenViewModel splashScreenViewModel);
@Binds
@IntoMap
@ViewModelKey(LoginActivityViewModel.class)
@rohankandwal
rohankandwal / CustomViewModelFactory.java
Last active May 10, 2018 10:55
CustomViewModelFactory - Used to provide ViewModels with all injections available for that particular Activity/Fragment/Service
@Singleton
public class CustomViewModelFactory implements ViewModelProvider.Factory {
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;
@Inject
CustomViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
this.creators = creators;
}
@NonNull