Fueling Curiosity, One Insight at a Time
At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
Dec 20, 2023
In Flutter, widgets are the building blocks of your UI (similar to components in React), and there are mainly 3 type of widgets based on how they handle state: Stateless, Stateful, and Inherited widgets
Stateless Widgets:
- Stateless widgets are immutable i.e. their configuration cannot change once they are created. They represent parts of your UI that don't depend on any mutable state.
- Stateless widgets rebuild when their parent widget or the widget hierarchy above them rebuilds and when an Inherited widget it depends on changes
Stateful Widgets:
- Stateful widgets are mutable and holds some internal state that can change over time. They are used when a part of your UI depends on dynamic data or user interactions.
- Stateful widgets rebuild when their internal state changes. State updates are handled using
Inherited Widgets:
- Inherited widgets are a special type of widget used to share data or state across an entire widget subtree without having to pass the data explicitly to every widget in the subtree (concept of Inherited widget is similar to Context API in React)
- Whenever the value inside Inherited widget changes, the widgets dependent on this widget get rebuilt.
Stateless Widgets:
- Stateless widgets are immutable i.e. their configuration cannot change once they are created. They represent parts of your UI that don't depend on any mutable state.
- Stateless widgets rebuild when their parent widget or the widget hierarchy above them rebuilds and when an Inherited widget it depends on changes
Stateful Widgets:
- Stateful widgets are mutable and holds some internal state that can change over time. They are used when a part of your UI depends on dynamic data or user interactions.
- Stateful widgets rebuild when their internal state changes. State updates are handled using
setState() which also triggers a rebuild of the widget and its subtree. They can also rebuild when their parent widget or the widget hierarchy above them rebuilds.Inherited Widgets:
- Inherited widgets are a special type of widget used to share data or state across an entire widget subtree without having to pass the data explicitly to every widget in the subtree (concept of Inherited widget is similar to Context API in React)
- Whenever the value inside Inherited widget changes, the widgets dependent on this widget get rebuilt.
Sujay
Dec 19, 2023
Difference between dynamic and Object type in dart
dynamic : dynamic is incredibly flexible. It tells Dart compiler to skip the type checking at compile time while type checking happens at run time. This is helpful when working with data of uncertain types.
dynamic value = 42;
value = 'Sujay';
print(value.isEven); // Error thrown during runtimeObject : Object is the root class for all other classes. Its like a container like that can hold any value. Since Object is generic, you won't have access to specific methods or properties of value without type casting
Object value = 42;
print(value.isEven); // throws compile time errorSujay
Dec 19, 2023
When running a javascript/typescript file during build time that requires environment variables importing
dotenv config gets the job done. Alternate approach is to have values in package.json that goes against the idea of having the environment variables as secrets and hidden from the repository code.Vaibhav Yadav
Senior System Analyst
Dec 18, 2023
In a web application, there can be scenarios where certain data needs to be fetched conditionally. For eg, in application with multiple user roles, there might be a specific role for which certain data is not needed. In such a case, we might want to avoid making unnecessary API calls to fetch that data. However, due to React's rules of hooks, we cannot directly
If you're using a library like
Here the
conditionally call a hook which fetches data.If you're using a library like
react-query and if you do not want to create a wrapper component to fetch the data, react-query provides a good solution. react-query has an enabled option for its useQuery hook. We can conditionally enable or disable the query based on our needs.
const { data, isLoading } = useQuery(
['user', userId],
fetchUserData,
{ enabled: isAuthenticated }
);Here the
useQuery is only executed if isAuthenticated is true. If isAuthenticated is false, the query is skipped.Ashwani Kumar Jha
Senior System Analyst
Dec 14, 2023
Use environmental variables in flutter
- Install flutter_dotenv package
- Create a .env file in the root of your project
- Add your variables to the .env file
- In order for the package to load .env file, add it to asset bundle in pubspec.yaml
- Load the contents of env into flutter, by adding this is main.dart
- Access the env variable like this
- Install flutter_dotenv package
- Create a .env file in the root of your project
- Add your variables to the .env file
- In order for the package to load .env file, add it to asset bundle in pubspec.yaml
flutter:
assets:
- .env (path to the file where env is stored)- Load the contents of env into flutter, by adding this is main.dart
void main() async {
await dotenv.load();
runApp(const MyApp());
}- Access the env variable like this
dotenv.env['APP_ENVIRONMENT']Sujay
Dec 13, 2023
below are the generator helper methods used to perform various actions in files and directories
• copy_file
• create_file
• insert_into_file
• inside
• gsub_file
• copy_file
• create_file
• insert_into_file
• inside
• gsub_file
Satya
Dec 12, 2023
generate generator by doing
This will create the below files for you
bin/rails generate generator initializer .This will create the below files for you
create lib/generators/initializer
create lib/generators/initializer/initializer_generator.rb
create lib/generators/initializer/USAGE
create lib/generators/initializer/templates
create spec/generator/initializers_generator_spec.rbSatya
Dec 12, 2023
Slack apps best practices and User experience - https://api.slack.com/best-practices
Hilda
Dec 4, 2023
How we can Set up Puma as Systemd service in Ubuntu 18 for Rails application, The main purpose is ,
• to ensure it starts automatically on boot,
• can be managed easily with systemd's service management commands,
• It also allows for better process management, automatic restarts in case of failure, and logging capabilities,
• few set of commands used to create puma.service file and getting it started:
for file creation :
• to ensure it starts automatically on boot,
• can be managed easily with systemd's service management commands,
• It also allows for better process management, automatic restarts in case of failure, and logging capabilities,
• few set of commands used to create puma.service file and getting it started:
for file creation :
/etc/systemd/system/puma.servicesudo systemctl daemon-reloadsudo systemctl enable pumasudo service puma startsudo service puma statusSoniya Rayabagi
Nov 30, 2023
Retrieving Command History with FZF
Command: To view the command history, we can use the following command:
Note: Ensure that you have FZF installed before. It provides an efficient way to navigate through past commands.
Command: To view the command history, we can use the following command:
history | fzfNote: Ensure that you have FZF installed before. It provides an efficient way to navigate through past commands.
Nisanth
Showing 36 to 38 of 82 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals
- Address
2nd Floor, Zee Plaza,
No. 1678, 27th Main Rd,
Sector 2, HSR Layout,
Bengaluru, Karnataka 560102 - Contact
hello@codemancers.com
+91-9731601276