This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun AnnotatedClickableText() { | |
val termsUrl = "https://example.com/terms" | |
val privacyUrl = "https://example.com/privacy" | |
val annotatedText = buildAnnotatedString { | |
append("You agree to our ") | |
withStyle(style = SpanStyle(color = Color.Blue, fontWeight = FontWeight.Bold)) { | |
appendLink("Terms of Use", termsUrl) | |
} | |
append(" and ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
class LRUCache<K, T>(private val capacity: Int) { | |
private val map: LinkedHashMap<K, T> = LinkedHashMap() | |
operator fun get(key: K): T? { | |
val value = map[key] | |
if (value != null) { | |
this[key] = value | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.geom.Dimension2D | |
data class DimensionDouble(private var width: Double, private var height: Double) : Dimension2D() { | |
override fun getWidth(): Double { | |
return width | |
} | |
override fun getHeight(): Double { | |
return height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object HttpStatus { | |
const val CONTINUE = 100 | |
const val SWITCHING_PROTOCOLS = 101 | |
const val PROCESSING = 102 | |
const val OK = 200 | |
const val CREATED = 201 | |
const val ACCEPTED = 202 | |
const val NON_AUTHORITATIVE_INFORMATION = 203 | |
const val NO_CONTENT = 204 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:typed_data'; | |
import 'package:meta/meta.dart'; | |
import 'package:web_socket_channel/io.dart'; | |
import 'package:uuid/uuid.dart'; | |
final uuid = Uuid(); | |
//var net = require('net'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/scheduler.dart'; | |
import 'package:flutter/widgets.dart'; | |
/// There's an alternative and better way to achieve this by using RenderObject / CustomMultiChildLayout but I will not cover it here. | |
class MyTextInput extends StatefulWidget { | |
@override | |
_MyTextInputState createState() => _MyTextInputState(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'TextField without padding', | |
debugShowCheckedModeBanner: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can use this extension I wrote (requires Dart 2.6): | |
extension GlobalKeyEx on GlobalKey { | |
Rect get globalPaintBounds { | |
final renderObject = currentContext?.findRenderObject(); | |
var translation = renderObject?.getTransformTo(null)?.getTranslation(); | |
if (translation != null && renderObject.paintBounds != null) { | |
return renderObject.paintBounds | |
.shift(Offset(translation.x, translation.y)); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main(List<String> arguments) { | |
final cat = Cat.white; | |
print('cat name: ${cat.name}'); | |
cat.talk(); | |
} | |
enum Cat { | |
black, | |
white, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:async/async.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
void main() { | |
test("CancelableOperation with future", () async { | |
var cancellableOperation = CancelableOperation.fromFuture( | |
Future.value('future result'), | |
onCancel: () => {print('onCancel')}, | |
); |