Skip to content

Instantly share code, notes, and snippets.

import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
Future<BitmapDescriptor> createCustomMarkerBitmap(int markerNumber, String imageURL) async {
int markerWidth;
if (kIsWeb) markerWidth= 30; else markerWidth = 100;
List<LatLng> decodeEncodedPolyline(String encoded) {
List<LatLng> poly = [];
int index = 0, len = encoded.length;
int lat = 0, lng = 0;
BigInt Big0 = BigInt.from(0);
BigInt Big0x1f = BigInt.from(0x1f);
BigInt Big0x20 = BigInt.from(0x20);
while (index < len) {
int shift = 0;
@JS('navigator.geolocation') // navigator.geolocation namespace
library jslocation; // library name can be whatever you want
import "package:js/js.dart";
// locjs.getCurrentPosition(allowInterop((pos) => success(pos))
@JS('getCurrentPosition') // Accessing method getCurrentPosition from Geolocation API
external void getCurrentPosition(Function success(GeolocationPosition pos), Function error(var err), options);
@JS('watchPosition') // Accessing method watchPosition from Geolocation API
@BoHellgren
BoHellgren / gameclasses.dart
Last active September 24, 2020 17:12
Game final gameclasses.dart
import 'package:flame/position.dart';
import 'package:flutter/material.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'dart:math';
import 'package:flame/components/component.dart';
import 'package:flame/components/mixins/tapable.dart';
import 'package:flame/sprite.dart';
import 'package:flame/text_config.dart';
import 'i18n.dart';
@BoHellgren
BoHellgren / MyGame.dart
Last active April 21, 2020 14:34
Game MyGame class
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'dart:math';
class MyGame extends BaseGame {
static int kills;
static int target;
static final Paint paint = Paint();
static Rect progressIndicatorRect;
static double progressIndicatorLength;
Rect bgRect;
@BoHellgren
BoHellgren / main.dart
Last active April 17, 2023 02:05
Game main.dart final version
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flame/components/component.dart';
import 'package:flame/sprite.dart';
import 'package:flame/flame.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:firebase_admob/firebase_admob.dart';
// Create the following file with this command: flutter pub run flappy_translator
import 'i18n.dart';
@BoHellgren
BoHellgren / gnat.dart
Last active April 21, 2020 14:37
Gnat class
class Gnat extends SpriteComponent with Tapable {
Sprite sprite;
double xMax, yMax;
double xSpeed, ySpeed;
double spriteSize;
final spriteSpeed = 18.0;
final spriteMin = 30.0;
final spriteMax = 60.0;
bool wall = false;
bool remove = false;
@BoHellgren
BoHellgren / main.dart
Last active April 23, 2020 17:16
Game main.dart step 2
import 'package:flutter/material.dart';
import 'package:flame/components/component.dart';
import 'package:flame/sprite.dart';
import 'package:flame/flame.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'gameclasses.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@BoHellgren
BoHellgren / main.dart
Last active April 23, 2020 17:17
Game main.dart step 1
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@BoHellgren
BoHellgren / main.dart
Last active October 8, 2021 14:34
main.dart for MLKit version
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:camera/camera.dart';
import 'package:soundpool/soundpool.dart';
import 'dart:ui' as ui;
import 'dart:typed_data';
import 'package:image/image.dart' as imglib;
import 'package:flutter/foundation.dart';
import 'breedinfo.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';