Skip to content

Instantly share code, notes, and snippets.

View Amir-P's full-sized avatar
🎯
Playing Dart

Amir Panahandeh Amir-P

🎯
Playing Dart
View GitHub Profile
@Amir-P
Amir-P / main.dart
Created January 8, 2024 10:51
Flutter two dimensional viewport buildOrObtainChildFor issue
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@Amir-P
Amir-P / notification_consumer.dart
Created April 20, 2022 13:37
A `BlocConsumer` like widget for notifications (uses `NotificationBuilder` from `flutter/widgets`)
import 'package:flutter/widgets.dart';
typedef NotificationBuilderCallback<T extends Notification> = Widget Function(
BuildContext context, T? notification);
typedef NotificationCondition<T extends Notification> = bool Function(
T notification);
class NotificationConsumer<T extends Notification> extends StatefulWidget {
final NotificationBuilderCallback<T> builder;
@Amir-P
Amir-P / notification_builder.dart
Created November 21, 2021 12:20
Build widgets in response to notifications (Flutter)
import 'package:flutter/widgets.dart';
typedef NotificationBuilderCallback<T extends Notification> = Widget Function(
BuildContext context, T? notification);
typedef NotificationCondition<T extends Notification> = bool Function(
T notification);
class NotificationConsumer<T extends Notification> extends StatefulWidget {
final NotificationBuilderCallback<T> builder;
@Amir-P
Amir-P / monty_hall.py
Created March 26, 2021 06:46
Monty Hall problem simulation in Python
import random
iterations = 10000
change_selection = True
winning_result = []
for i in range(iterations):
doors = [0, 0, 0]
doors[random.randint(0, 2)] = 1
@Amir-P
Amir-P / date_range_picker.dart
Last active September 13, 2020 15:43
Flutter date range picker using private classes from Flutter's SDK
// Original source code is by The Flutter Authors and I changed it slightly to meet my needs.
import 'dart:math' as math;
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'date_utils.dart' as utils;
@Amir-P
Amir-P / converter.py
Last active October 2, 2023 09:41
Convert JSON exported contacts from Telegram to vCard (.vcf)
import sys
import json
input_file = sys.argv[1]
output_file = sys.argv[2]
output_file = open(output_file, 'w')
def to_vcf_string(first_name, last_name, phone):
vcf_lines = []
@Amir-P
Amir-P / itm_converter.py
Created June 2, 2020 07:37
Coordinate converter for ITM (IRENET95_Irish_Transverse_Mercator) to WGS-84 and vice versa with use of pyproj
import pyproj
class ITMConverter():
def __init__(self):
self.wgs84 = pyproj.Proj('epsg:4326')
self.itm = pyproj.Proj('epsg:2157')
def convert_to_wgs(self, easting, northing):
return pyproj.transform(self.itm, self.wgs84, easting, northing)
class BreadCrumbNavigator extends StatelessWidget {
final List<Route> currentRouteStack;
BreadCrumbNavigator() : this.currentRouteStack = routeStack.toList();
@override
Widget build(BuildContext context) {
return RowSuper(
children: List<Widget>.from(currentRouteStack
.asMap()
class CategoriesPage extends StatelessWidget {
static MaterialPageRoute getRoute() => MaterialPageRoute(
settings: RouteSettings(name: 'Categories'),
builder: (context) => CategoriesPage());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [AppNavigatorObserver()],
home: HomePage(),
);
}
}