This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Recipies> getRecipies(String? timeOfDay) { | |
if(timeOfDay == "noon") { | |
return foodApi.getAllNoonFood(); | |
} else { | |
return foodApi.getAllMorningFood(); | |
} | |
// This code will never execute | |
return foodApi.getAllEveningFood(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bad practive | |
if(recipe.forLunch()); | |
getIngredients(); | |
// Once it is formatted by dart formatter | |
if(recipe.forLunch()) ; | |
getIngredients(); | |
//Good practice | |
if(recipe.forLunch()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return GetMaterialApp( | |
theme: ThemeData( | |
primarySwatch: Colors.blue, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Other code | |
GetPage( | |
name: AppLinks.DASHBOARD, | |
page: () => Dashboard(), | |
middlewares: [ | |
// Add here | |
AuthGuard(), | |
], | |
children: [ | |
GetPage( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FavoritesBinding extends Bindings { | |
@override | |
void dependencies() { | |
// Lazily inject the dependency and only use the dependency when needed. | |
Get.lazyPut(() => FavoritesController()); | |
} | |
} | |
/* | |
***Other Code** |
OlderNewer