Skip to content

Instantly share code, notes, and snippets.

View vferreirati's full-sized avatar
😎

Victor Ferreira vferreirati

😎
View GitHub Profile
// Other stuff ...
private lateinit var viewModelFactory: ViewModelFactory
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initViews()
viewModelFactory = ViewModelFactory(NotesRepository(this))
// This is the NotesList activity Component (Which could be turned into a generic one)
component = DaggerNotesActivityComponent
.builder()
.notesActivityModule(NotesActivityModule(this)) // Extra step, since the module requires the context to provide a RecyclerViewAdapter
.notesApplicationComponent(NotesApplication.get(this).getComponent())
.build()
// This is the EditorActivity Component (The one which would be deleted in favor of the generic one)
component = DaggerEditorActivityComponent
.builder()
@vferreirati
vferreirati / BeerRepository.kt
Last active October 18, 2018 13:31
Basic entity repository using coroutines instead of AsyncTasks
package com.vferreirati.cervejeiros.repository
import androidx.lifecycle.MutableLiveData
import com.vferreirati.cervejeiros.data.dao.BeerDao
import com.vferreirati.cervejeiros.data.model.Beer
import com.vferreirati.cervejeiros.services.PunkService
import com.vferreirati.cervejeiros.services.model.BeerResponse
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.launch
class BeerListViewModel (private val beerRepository: BeerRepository): ViewModel(), CoroutineScope {
private var job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
fun getBeers(): LiveData<List<BeerResponse>> {
val beers = MutableLiveData<List<BeerResponse>>()
launch {
@vferreirati
vferreirati / cs
Last active August 31, 2019 19:39
dart live templates
import 'package:chopper/chopper.dart';
part '$FILENAME$.chopper.dart';
@ChopperApi(baseUrl: '')
abstract class $SERVICE_NAME$ extends ChopperService {
static $SERVICE_NAME$ create([ChopperClient client]) => _$$$SERVICE_NAME$(client);
// endpoints
}
Future<Event<bool>> login(LoginModel loginModel) async {
try {
final loginResponse = await _authService.login();
return SuccessEvent(data: true);
} catch(e) {
if(e is SocketException) {
// Usuário sem internet
}
}
}
@vferreirati
vferreirati / print.dart
Created September 20, 2019 17:01
Exemplo de geração de imagem a partir de um widget
void _onShareReceipt(context) async {
final data = await _onCaptureReceipt();
// Utilizando o pacote "esys_flutter_share" para compartilhamento da imagem gerada
await Share.file('Comprovante de Venda', 'comprovante.png', data, 'image/png');
}
Future<Uint8List> _onCaptureReceipt() async {
// _receiptKey é uma GlobalKey que foi atribuida ao Widget pelo qual desejo imprimir
RenderRepaintBoundary boundary = _receiptKey.currentContext.findRenderObject();
class _FirstSchedulePageState extends State<FirstSchedulePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.PAGE_BACKGROUND_COLOR,
body: _buildContent(),
);
}
Widget _buildContent() {
import 'package:agendador_mobile/src/core/resources/app_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
class MainText extends StatelessWidget {
final String text;
final FontWeight fontWeight;
final TextSize textSize;
final Color textColor;
final bool allCaps;
private fun checkLocationPermission() {
TedPermission.create()
.setPermissionListener(object : PermissionListener {
override fun onPermissionDenied(deniedPermissions: MutableList<String>?) {}
override fun onPermissionGranted() {
viewModel.onAction(ScreenActions.OnLocationPermissionGranted)
}
})
// ACCESS_FINE_LOCATION is being used due to the yuno SDK