Transparent NavBar with persistent_bottom_nav_bar - flutter

I am using persistent_bottom_nav_bar package:
https://pub.dev/packages/persistent_bottom_nav_bar
which does exactly what I want, except it is missing an important Scaffold function:
extendBody: true
The package tells me the following:
NOTE: This widget includes SCAFFOLD (based on CupertinoTabScaffold),
so no need to declare it.
I am looking for a solution to be able have extendedBody: true while using this package

What you can do is modify the package, and add this property to the built-in scaffold.
1- Go to the package directory, example:
C:\Users\UserName\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\PackageFolderName
2- Copy the Package to your project (the whole PackageFolderName, and paste at same level with pubspec.yaml )
3- Modify the Package's code, i.e. find the Scaffold and add the property
4- Modify your Project's pubspec.yaml and change the path of the package to
Package Name:
path: ./PackageFolderName/
5- Save your pubspec.yaml

Related

Display an image from the asset in the documentation

I'm writing documentation about a variable and I would like to include an image that is inside the project. For example:
assets/
|- icons/
| |- my-image.svg
lib/
|- my_file.dart
I know it is possible to display an image from an URL, but what about one from a file?
Those were my unsuccessful tries:
// lib/my_file.dart
/// The image attempt:
/// ![](assets/icons/my-image.svg)
/// ![](../assets/icons/my-image.svg)
const myVariable = 0;
But it doesn't work:
Is there a way to do it?
There is already an issue on GitHub: #2390
and also a related thread: Using local image assets in dart documentation comments
Effectively, web urls are working, but relative paths aren't, because VSCode doesn't support that. It tries to open the files relative to its application directory. But I can't confirm that for Windows either, because for me, not even absolute paths are working...
So if your project lives in a public repository anyways, you could just use a web url.
1:open pubspec.yaml and click "Pub get"
2:
Image.asset("assets/icons/my-image.svg",width: 100,height: 100,)
So i think you want to let the variable hold the asset image path so do this
Go to pubspecs.yaml file and add this
flutter:
assets:
- assets/icons/my-image.svg
Then run flutter pub get
then you can use the image this way
//let the variable hold the image path
const myVariable = "assets/icons/my-image.svg";
//to display on widget
Image.asset(myVariable);

Using a custom icon font in a Flutter package displays Question marks instead of custom icons

I have an application composed of a number of different Dart and Flutter packages.
This has proven useful in that I've been able to move things like fonts, colours and Widgets into an independent style guide package which we can then use across all of our other applications.
Using custom fonts in a package works slightly differently in Flutter as we need to add the assets directory as a child of lib rather than a sibling:
…and then register these assets in pubspec.yaml like so:
assets:
- packages/receipt_widget/assets/fonts/my_font.ttf
// other asset declarations
This, for custom fonts and icons (png, jpg etc) works completely fine. My issue is that the same approach does not work for custom icon fonts.
Steps:
Generate custom icon font using IcoMoon or Flutter Icon
Place the generated font into the assets/fonts directory as demonstrated above
Place the generated dart file into the lib folder
Reference the custom icon in code and place into an Icon widget like so:
Icon(MyFontIcon.ic_heart);
For safety I then run flutter clean and uninstall the app from the device/ emulator before deploying a clean build.
I'm then left with a question mark rather than the referenced icon.
NB. the very same icons work correctly when used in a Flutter application directly rather than in a package.
To use your Flutter Icon font from a custom package, you can follow these steps:
(I repeated some of your steps already, for others who will find this issue)
create a flutter icon font
You can use flutter icon for that https://www.fluttericon.com
Put the file into your package
Make sure to copy the .ttf file into of the /lib folder.
NOT just assets, as you would do in your root project.
Example path:
/packages/my_awesome_fontpackage/lib/assets/MyIconFont.ttf
(see https://zubairehman.medium.com/how-to-use-custom-fonts-images-in-flutter-package-c2d9d4bfd47a )
Add the font to your project
Now open your package's pubspec.yaml file and add the font as an asset with package path:
flutter:
fonts:
- family: MyIconFont
fonts:
- asset: packages/my_awesome_fontpackage/assets/MyIconFont.ttf
(you might have to restart your app and bundling completely for the font to be loaded correctly and maybe run flutter clean just to be sure)
Now add package declaration to font dart file
Go into the my_icon_font.dart file and change the constant _kFontPkg there to your package name.
class MyIconFont {
MyIconFont._();
static const _kFontFam = 'MyIconFont';
static const String? _kFontPkg = 'my_awesome_fontpackage';
static const IconData bell = ...
....
}

I want to use the icon of vaccine but it does not work when I add its code

this is my code for that :-
Icon(
Icons.vaccines_outlined,
),
I get this error when I added the code:-
The getter 'vaccines_outlined' isn't defined for the type 'Icons'.
Try importing the library that defines 'vaccines_outlined', correcting the name to the name of an existing getter, or defining a getter or field named 'vaccines_outlined'.
where did you find this icon! it seems that flutter icons do not have this one! Search through the icons in this link
If you are refering to the Material Icon "vaccines" as here.
You should download it and add it to your assets as it is not present in the flutter library yet.
If you don't know how to add an assets please refer to this documentation
You need to add it to your pubspec.yaml and copy it in your assets folder.

Flutter: How to get the local AssetBundle when being used as a package?

I am trying to nest 1 flutter application within another, think a Gallery App, that links to many Demo Apps:
Gallery
--> Demo1
--> Demo2
etc
Demo1 uses: rootBundle.load('images/image.png') to load images.
This breaks when Demo1 is used from within Gallery, presumably because rootBundle now refers to the Gallery Bundle, not Demo 1.
Is there a way I can architect Demo1 so it always pulls from it's own AssetBundle? I tried
bundle = DefaultAssetBundle.of(context);
but it does not seem to make a difference.
NOTE: I can work around this, by moving the images inside of /lib, and declaring them as 'packages/package_name/images/glow.png', and then using rootBundle.load('packages/package_name/images/glow.png'), however we're looking to avoid this requirement, and instead just access the correct AssetBundle.
I think you could wrap the screens or widgets of the included apps with a DefaultAssetBundle, and hand it a custom implementation of PlatformAssetBundle in which you overwrite its load(String) method. In it you prefix the key parameter with the package name. The package name could be provided as a constructor parameter of your custom implementation. Example:
Container(
child: DefaultAssetBundle(
bundle: PackageAssetBundle(packageName: 'demo1'),
child: Demo1WidgetWithPackageAssets(),
),
)

Is there a snapHelper in flutter?

I am searching for snapHelper in flutter, somthing like
SnapHelper
Is there a widget like this?
How do I get it in other ways?
There is a widget flutter_swiper ,I think this widget looks like what you are looking for
and you can get the example code from flutter_swiper example tab
paste into a dart file and run it to get more knowledge about what this package can do.By the way you need to add your pubspec.yaml file like this:
dependencies:
# other dependencies
flutter_swiper: ^1.1.4