Skip to content

Instantly share code, notes, and snippets.

View yshean's full-sized avatar

Yong Shean yshean

  • Comerge Solutions
  • Kuala Lumpur, Malaysia
  • X @shin_chong
View GitHub Profile
@yshean
yshean / network_image_test.dart
Last active July 1, 2022 10:43
Unit / widget test: test the NetworkImage or Image.network properties
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail_image_network/mocktail_image_network.dart';
testWidgets(
'renders an image with the provided image url',
(tester) async {
const expectedImageUrl = 'media.giphy.com/example.jpg';
await mockNetworkImages(() async {
await tester.pumpWidget(app); // your app is a widget that contains your network image
/** You should also wrap your NetworkImage or Image.network with a DecoratedBox or other widget as the parent,
import 'package:firebase_messaging/firebase_messaging.dart';
class PushNotificationService {
final FirebaseMessaging _fcm;
PushNotificationService(this._fcm);
Future initialise() async {
if (Platform.isIOS) {
_fcm.requestNotificationPermissions(IosNotificationSettings());
class MyApp extends StatelessWidget {
static final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
Widget build(BuildContext context) {
final pushNotificationService = PushNotificationService(_firebaseMessaging);
pushNotificationService.initialise();
// the rest of your build method
}
}
import 'package:flutter/material.dart';
import 'package:google_places_flutter/address_search.dart';
import 'package:google_places_flutter/place_service.dart';
import 'package:uuid/uuid.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
class Place {
String streetNumber;
String street;
String city;
String zipCode;
import 'package:flutter/material.dart';
import 'package:google_places_flutter/address_search.dart';
import 'package:google_places_flutter/place_service.dart';
import 'package:uuid/uuid.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@yshean
yshean / place_service_v1.dart
Created June 1, 2020 04:19
Place service v1 with autocomplete
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
// For storing our result
class Suggestion {
final String placeId;
final String description;
@yshean
yshean / address_search_v1.dart
Created June 1, 2020 04:07
Address search v1
import 'package:flutter/material.dart';
class AddressSearch extends SearchDelegate<Suggestion> {
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
tooltip: 'Clear',
icon: Icon(Icons.clear),
onPressed: () {
@yshean
yshean / main_with_search.dart
Last active June 1, 2020 03:54
TextField setup for address input v2
import 'package:flutter/material.dart';
import 'package:google_places_flutter/address_search.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
@yshean
yshean / main_initial.dart
Last active June 1, 2020 03:52
Simple TextField setup for address input
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {