Skip to content

Instantly share code, notes, and snippets.

View sagar2093's full-sized avatar

Sagar Chapagain sagar2093

View GitHub Profile
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(const CalendarGeneratorApp());
}
class CalendarGeneratorApp extends StatelessWidget {
const CalendarGeneratorApp({super.key});
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@sagar2093
sagar2093 / AndroidManifest.xml
Created May 22, 2020 14:38
Android Manifest of app module
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jetpackcompose">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
@sagar2093
sagar2093 / build.gradle
Last active May 22, 2020 14:30
compose module level build.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
@sagar2093
sagar2093 / build.gradle
Created May 22, 2020 14:06
compose top level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.71'
def compose_release_version = "dev11"
ext.compose_version = "0.1.0-$compose_release_version"
ext.compose_compiler_extension_version = "0.1.0-$compose_release_version"
repositories {
google()
jcenter()
@Preview
@Composable
private fun UniversityCardPreview() {
val university = University(uniName = "Harvard University", uniAddress = "United States")
MaterialTheme {
UniversityCard(university)
}
}
@Composable
fun UniversityCard(university: University) {
Box(padding = 8.dp) {
Card(
shape = RoundedCornerShape(4.dp),
elevation = 4.dp,
color = Color.White
) {
Clickable(
modifier = Modifier.ripple(),
// normal function
fun showGreeting(name:String){
// tv_greeting is defined in xml layout
tv_greeting.text = "Hello $name"
}
// composable function
@Composable
fun GreetingText(name:String){
Text(text = "Hello $name")
@sagar2093
sagar2093 / SharedPreference.kt
Created July 4, 2019 12:00
Extension function for `SharedPreferences` by Google.
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sagar2093
sagar2093 / Utils.java
Last active June 29, 2021 13:40
Zpl converter for converting image to zpl code (hex ascii format) for printing through zebra printers. The converted code can be checked at http://labelary.com/viewer.html
public class Utils {
public static String getZplCode(Bitmap bitmap, Boolean addHeaderFooter) {
ZPLConverter zp = new ZPLConverter();
zp.setCompressHex(true);
zp.setBlacknessLimitPercentage(50);
Bitmap grayBitmap = toGrayScale(bitmap);
return zp.convertFromImage(grayBitmap, addHeaderFooter);
}