Skip to content

Instantly share code, notes, and snippets.

@mehmetf
mehmetf / cache_control.dart
Created August 17, 2017 15:04
Implementing cache control on Flutter
class CacheControl extends WidgetsBindingObserver {
CacheControl() {
WidgetsBinding.instance.addObserver(this);
}
void _cleanAllCache() {
// Cleans all cache.
}
@override
@mehmetf
mehmetf / secure_window.m
Created August 17, 2017 15:06
secure window on iOS
// Hide your app’s key window when your app will resign active.
— (void)applicationWillResignActive:(UIApplication *)application {
self.window.hidden = YES;
}
// Show your app’s key window when your app becomes active again.
— (void)applicationDidBecomeActive:(UIApplication *)application {
self.window.hidden = NO;
}
@mehmetf
mehmetf / secure_window_color.m
Created August 17, 2017 15:07
secure window with color
- (void)applicationWillResignActive:(UIApplication *)application {
UIView *__autoreleasing colorView =
[[UIView alloc] initWithFrame:self.window.frame];
// Can be any integer you’re not using as a tag.
colorView.tag = 9999;
// Here we used white as the subview color.
colorView.backgroundColor = [UIColor whiteColor];
[self.window addSubview:colorView];
[self.window bringSubviewToFront:colorView];
@mehmetf
mehmetf / navigation_builder.dart
Created September 3, 2017 03:18
Navigation Builder Pattern
/// Platform agnostic navigation definition.
class NavigationItem {
final Icon icon;
final String title;
final VoidCallback onTap;
NavigationItem({this.icon, this.title, this.onTap});
}
/// Helper for returning platform specific navigation items.
var navItems = <NavigationItem>[
new NavigationItem(
icon: const Icon(Icons.home),
title: 'Home',
onTap: () => Navigator.pushNamed(context, '/')),
new NavigationItem(
icon: const Icon(Icons.change_history),
title: 'Hidden',
onTap: () => Navigator.pushNamed(context, '/hidden')),
];
class ScaffoldWithNavigation extends StatelessWidget {
final List<NavigationItem> navItems;
final NavigationItem selectedItem;
final AppBar appbar;
final Widget body;
final FloatingActionButton button;
ScaffoldWithNavigation({
this.appbar,
this.navItems,
@mehmetf
mehmetf / paramed_widget.dart
Last active May 8, 2020 19:34
Passing Params
class MyPage extends StatelessWidget {
final int accountId;
final int scopeId;
MyPage(this.accountId, this.scopeId);
Widget build(BuildContext context) {
return new MyWidget(accountId, scopeId);
}
}
@mehmetf
mehmetf / with_inherited_widget.dart
Last active October 20, 2017 04:09
With Inherited Widget
class MyInheritedWidget extends InheritedWidget {
final int accountId;
final int scopeId;
MyInheritedWidget(accountId, scopeId, child): super(child);
@override
bool updateShouldNotify(MyInheritedWidget old) =>
accountId != old.accountId || scopeId != old.scopeId;
}
@mehmetf
mehmetf / large_context.dart
Last active October 20, 2017 04:54
Large Context
class MyAppContext {
int teamId;
String teamName;
int studentId;
String studentName;
int classId;
...
}
@mehmetf
mehmetf / split_context.dart
Created October 20, 2017 04:59
Split Context
class TeamContext {
int teamId;
String teamName;
}
class StudentContext {
int studentId;
String studentName;
}