I often times import cupertino.dart instead of material.dart when having to import widgets because its the first suggested options.
Its not a real problem but for the sake of consistency I want to prevent importing cuppertino.dart so it is not listed in the import suggestions and only use widgets.dart or material.dart instead.
Is there a way to configure Android Studio or Dart Analyzer to prevent cuppertino.dart to show in suggestions?
Seems no, but there is a workaround: You can write a linter to examine your code and warn (or error) whenever you see imports of cupertino.dart. That linter can even automatically correct the code (by replacing cupertino with material).
Some methodology thoughts: I often want something to be automatically performed ("import material not cupertino" in your case); but later I realized it is hard or not exist yet, but some verifier is good enough ("manually import; but warn if you import the wrong one").
You can create an export file with your exports inside and call this file afterwards.
For example create an exportsFile:
export 'package:flutter/material.dart';
And now call this file when you wants:
import 'exportsFile.dart';
Related
I try to implement Google Play Pay but don`t know how solve this problem:Type of ImmutableList cannot be resoclved.
Should I import some package?
I have search with Google and no any question like this(Android studio)
ImmutableList.of(QueryProductDetailsParams.Product.newBuilder()
.setProductId("product_id_example")
.setProductType(BillingClient.ProductType.SUBS)
.build())
Android Studio suggests the firebase-crashlytics-buildtools dependency to import the ImmutableList class. Doing so resulted in a big increase of the file (bundle) size.
Try instead including guava as a dependency, if you are not using crashlythics in your app:
// graddle
implementation 'com.google.guava:guava:31.1-android'
// java class/code
import com.google.common.collect.ImmutableList;
This has a much smaller impact on the file size. In my case, the bundle was 2MB compared to 10 MB if using crashlythics-buildtools.
I run into the same problem. By hovering with the pointer over 'ImmutableList' I selected the entry Add dependency on com.google.firebase:firebase-crashlitics-builtools and import...
This action created the following line in the import section of my activity file
import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.collect.ImmutableList;
and the following line in the build.gradle file:
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.7.1'
However, the word reloc in the import line initially appeared in red color with the hint Cannot resolve symbol 'reloc'. Then I noticed that in the build.gradle file, android studio was offering to change the version of the crashlytics-buildtools from 2.7.1 to 2.9.1. After doing so and syncing gradle, the word reloc was no longer red and ImmutableList was recognized correctly.
I wonder whether it is really necessary to import the firebase crashlytics-buildtools for the integration of the Google Billing Library (I use it for an app with in-app purchases) or if there is a more simple way to do this.
Sometimes I see slightly different imports
import styled, { withTheme } from "styled-components/macro";
import styled, { withTheme } from "styled-components";
Since they have the same functionality I cannot understand the difference between them neither can google anything that could help.
In production styled-components generates unique hashes for css classes like .eeZmbc or .ZzNLl. These are used for saving space but are not useful for developers in development.
For semantic class names in development a babel plugin exists. It generates names like .Navbar__Item-sc-14eztoj-1 as in .FileName__StyledComponent-generatedHash to help us trace an element/style back to its source.
So if you use create-react-app you can use this plugin without ejecting and without adding it to babel config. You just have change your import from styled-components to styled-components/macro. A quick find-and-replace in you IDE will do the trick.
All the compile-time code transformation is handled by babel-plugin-macros
babel-plugin-macros defines a standard interface for libraries that want to use compile-time code transformation without requiring the user to add a babel plugin to their build system (other than babel-plugin-macros, which is ideally already in place).
Personally I add the babel plugins to the config file manually and use standard imports like styled-components.
When I run gradlew ktlintCheck it fails with a lot of
Wildcard import (cannot be auto-corrected)
errors.
Create a .editorconfig file on root level and add amongst others:
disabled_rules=no-wildcard-imports
Came across this ktlint-gradle issue where it discussed about support to be added to ktlint-gradle for --disabled_rules. It eventually got included and a new cleaner way of disabling no-wildcard import check is as following.
ktlint {
enableExperimentalRules.set(true)
disabledRules.set(setOf("experimental:package-name", "no-wildcard-imports"))
}
FYI: Following rationale made --disabled_rules support possible.
Is there a way to have custom behaviour for import statements in Python? How? E.g.:
import "https://github.com/kennethreitz/requests"
import requests#2.11.1
import requests#7322a09379565bbeba9bb40000b41eab8856352e
Alternatively, in case this isn't possible... Can this be achieved in a standard way with function calls? How? E.g.:
import gitloader
repo = gitloader.repo("https://github.com/kennethreitz/requests")
requests = repo.from_commit("7322a09379565bbeba9bb40000b41eab8856352e")
There are two reasons for why I would like to do this. The first reason is convenience (Golang style imports). The second reason is that I need cryptographic verification of plugin modules for a project. I'm using Python 3.x
What you're essentially asking is customization of the import steps. This was made possible with PEP 302 which brought about certain hooks for for customization.
That PEP is currently not the source from which you should learn how importing works; rather, look at the documentation for the import statement for reference. There it states:
Python includes a number of default finders and importers. The first one knows how to locate built-in modules, and the second knows how to locate frozen modules. A third default finder searches an import path for modules. The import path is a list of locations that may name file system paths or zip files. It can also be extended to search for any locatable resource, such as those identified by URLs.
The import machinery is extensible, so new finders can be added to extend the range and scope of module searching.
In short, you'll need to define the appropriate finder (to find the modules you're looking for) and an appropriate loader for loading these.
So far I've seen the answer for Python2 however it doesn't work on Python3, I want to be able to always get the latest changes in a module that lives in a package every time the code runs without reopening a new interpreter every time. Since modules seems to be loaded just once for performance purposes as specified in documentation,I would like to be able to force a load in the modules programatically right before starting my program. Thanks in advance...
Although I'm not a fan of answering my own questions, I think in this case totally worth to mention it since seems to be quiet useful, in order to reload a module that you previously modified without having to restart the whole interpreter, just programatically forcing the modules (contained within a package) to get the latest changes this is the way to go:
import com.your.package.YourModule as MyModuleInPackage
import imp
imp.reload(MyModuleInPackage)
Notice that trying to use imp.reload(com.your.package.YourModule) causes an error, so the way to go is by having an Alias for the fully quialified name of the module and use it in the reload function to work properly...
Hope this helps.
Regards!