Skip to content

Instantly share code, notes, and snippets.

View VB10's full-sized avatar
🏠
Working from home

Veli Bacik VB10

🏠
Working from home
View GitHub Profile
Positioned positionedPageView(
BuildContext context, PointsCompleted completed) {
return Positioned(
height: context.dynamicHeight(0.12),
bottom: 0,
right: 0,
left: -context.dynamicWidth(0.1),
child: PageView.builder(
onPageChanged: (value) {
context
class PointsCompleted extends PointsState {
final List<Coordinate> coordinates;
final int selectedItem;
PointsCompleted(this.coordinates, {this.selectedItem});
PointsCompleted copyWith({
List<Coordinate> coordinates,
int selectedItem,
class RouteManager implements IRouteManager {
@override
double calculateDistance(LatLng cordinate, LatLng secondCordinate) {
return (distanceBetween(
cordinate.latitude, cordinate.longitude, secondCordinate.latitude, secondCordinate.longitude))
.roundToDouble() /
1000;
}
}
enum NetworkPath { LOGIN, BUILD_HOME }
extension NetworkPath on NetworkRoutes {
String get rawValue {
switch (this) {
case NetworkRoutes.LOGIN:
return 'login';
case NetworkRoutes.BUILD_HOME:
return 'house';
default:
@VB10
VB10 / lazy_load.dart
Created April 9, 2021 20:44
Flutter Lazy Load Extension for ListView
extension ListViewExtension on ListView {
Widget onLazyLoads(Future<void> Function() onPagingLoad, {Widget? itemLoadWidget}) {
final delegate = childrenDelegate as SliverChildBuilderDelegate;
final itemCount = delegate.childCount ?? 0;
return NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
if (notification.metrics.pixels == notification.metrics.maxScrollExtent) {
onPagingLoad();
}
return true;
extension StringExtension on String {
bool validateMinLenght([double value = 6]) {
return this.length > value;
}
}
@VB10
VB10 / locale_manager.dart
Last active April 18, 2021 02:10
Locale Manager
class LocaleManager {
static final LocaleManager _instance = LocaleManager._init();
SharedPreferences? _preferences;
static LocaleManager get instance => _instance;
/// [SharedPreferences] init constructor.
LocaleManager._init() {
SharedPreferences.getInstance().then((value) {
_preferences = value;
class LocaleSharedManager {
static final LocaleSharedManager _instance = LocaleSharedManager._init();
static LocaleSharedManager get instance => _instance;
late final SharedPreferences _preferences;
LocaleSharedManager._init() {
SharedPreferences.getInstance().then((value) {
_preferences = value;
});
}
abstract class IHomeService {
final INetworkManager manager;
IHomeService(this.manager);
Future<List<ItemModel>> fetchItem();
Future<Uint8List?> downloadFile(String url, ProgressCallback callback);
}
enum _HomeServicePath { CACHE }
test('Fetch Pdf And Cache', () async {
final response = await manager.downloadFileSimple('http://www.africau.edu/images/default/sample.pdf', null);
final directory = await getApplicationDocumentsDirectory();
await Directory('${directory.path}').create();
await Directory('${directory.path}/vb2').create();
final path = '${directory.path}/vb2/1.pdf';
final file = File(path);
final fileWithData = await file.writeAsBytes(response.data!);
expect(await fileWithData.exists(), true);
});