Skip to content

Instantly share code, notes, and snippets.

View BrianMwas's full-sized avatar
🎯
Make it happen

Brian Mwangi BrianMwas

🎯
Make it happen
View GitHub Profile
analyzer:
exclude:
- build/**
- lib/**.g.dart
errors:
missing_return: error
dead_code: error
always_declare_return_types: error
avoid_web_libraries_in_flutter: error
missing_required_param: error
Future<Recipies> getRecipies(String? timeOfDay) {
if(timeOfDay == "noon") {
return foodApi.getAllNoonFood();
} else {
return foodApi.getAllMorningFood();
}
// This code will never execute
return foodApi.getAllEveningFood();
}
// Bad practive
if(recipe.forLunch());
getIngredients();
// Once it is formatted by dart formatter
if(recipe.forLunch()) ;
getIngredients();
//Good practice
if(recipe.forLunch())
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
@BrianMwas
BrianMwas / main_getx.dart
Created July 31, 2021 20:26
Getx main file with navigation management
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
// Going to a page
Get.toNamed(AppLinks.DASHBOARD);
// Move back one page only
Get.offNamed(AppLinks.LOGIN);
// Going back all route/pages until LOGIN page you can even pass a predicate/ condition to pop until that condition passes
Get.offAllNamed(AppLinks.LOGIN);
class AuthGuard extends GetMiddleware {
// Get the auth service
final authService = Get.find<AuthService>();
// The default is 0 but you can update it to any number. Please ensure you match the priority based
// on the number of guards you have.
@override
int? get priority => 1;
@override
// Other code
GetPage(
name: AppLinks.DASHBOARD,
page: () => Dashboard(),
middlewares: [
// Add here
AuthGuard(),
],
children: [
GetPage(
// Can be called within controllers
void toDashboard() {
Get.to(
AppLinks.DASHBOARD,
// Transition as a property. Different transitions can be applied. Such as
// fade,
// fadeIn,
// rightToLeft,
// leftToRight,
// upToDown,
class FavoritesBinding extends Bindings {
@override
void dependencies() {
// Lazily inject the dependency and only use the dependency when needed.
Get.lazyPut(() => FavoritesController());
}
}
/*
***Other Code**