Skip to content

Instantly share code, notes, and snippets.

Avatar

Rohan Kandwal rohankandwal

  • Bengaluru, Karnataka, India
View GitHub Profile
View analysis_options.yaml
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 Nov 28, 2019
Loading a url into the webview
View Flutter: Webview loading URL
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 Nov 27, 2019
Showing widgets between ListView items in Flutter
View Flutter Image as ListView Separator
@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 Nov 27, 2019
Adding divider to Flutter's ListView using a Separator
View Flutter Seperated ListView
@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 Nov 27, 2019
Basic Flutter ListView implementation
View Flutter ListView
@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
RxSchedulersOverrideRule - subscriptions always subscribeOn and observeOn Schedulers.trampoline().
View RxSchedulersOverrideRule.java
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
AppModule - Used to inject fragments, service, activities with other modules
View AppModule.java
@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
ViewModelModule - Module to bind your ViewModels. We also bind our custom ViewModelFactory here.
View ViewModelModule.java
@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
CustomViewModelFactory - Used to provide ViewModels with all injections available for that particular Activity/Fragment/Service
View CustomViewModelFactory.java
@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