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
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:firebase_messaging/firebase_messaging.dart';
class PushNotificationService {
final FirebaseMessaging _fcm;
PushNotificationService(this._fcm);
Future initialise() async {
if (Platform.isIOS) {
_fcm.requestNotificationPermissions(IosNotificationSettings());
@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,