Basics

Assets

Introduction

Nylo Website v7 provides helper methods for managing assets in your Flutter app. Assets are stored in the assets/ directory and include images, videos, fonts, and other files.

The default asset structure:

assets/
├── images/
│   ├── nylo_logo.png
│   └── icons/
├── fonts/
└── videos/

Displaying Images

Use the LocalAsset() widget to display images from the assets:

import 'package:nylo_framework/nylo_framework.dart';

// Basic usage
LocalAsset.image("nylo_logo.png")

// Using the `getImageAsset` helper
Image.asset(getImageAsset("nylo_logo.png"))

Both methods return the full asset path including the configured asset directory.

Custom Asset Paths

To support different asset subdirectories, you can add custom constructors to the LocalAsset widget.

// /resources/widgets/local_asset_widget.dart
class LocalAsset extends StatelessWidget {
  // images
  const LocalAsset.image(String assetName,
      {super.key, this.width, this.height, this.fit, this.opacity, this.borderRadius})
      : assetName = "images/$assetName";

  // icons <- new constructor for icons folder
  const LocalAsset.icons(String assetName,
      {super.key, this.width, this.height, this.fit, this.opacity, this.borderRadius})
      : assetName = "images/icons/$assetName";
}

// Usage examples
LocalAsset.icons("icon_name.png", width: 32, height: 32)
LocalAsset.image("logo.png", width: 100, height: 100)

Returning Asset Paths

Use getAsset() for any file type in the assets/ directory:

// Video file
String videoPath = getAsset("videos/welcome.mp4");

// JSON data file
String jsonPath = getAsset("data/config.json");

// Font file
String fontPath = getAsset("fonts/custom_font.ttf");

Using with Various Widgets

// Video player
VideoPlayerController.asset(getAsset("videos/intro.mp4"))

// Loading JSON
final String jsonString = await rootBundle.loadString(getAsset("data/settings.json"));

Adding New Files

  1. Place your files in the appropriate subdirectory of assets/:

    • Images: assets/images/
    • Videos: assets/videos/
    • Fonts: assets/fonts/
    • Other: assets/data/ or custom folders
  2. Ensure the folder is listed in pubspec.yaml:

flutter:
  assets:
    - assets/images/
    - assets/videos/
    - assets/data/

Asset Configuration

Nylo Website v7 configures the asset path via the ASSET_PATH environment variable in your .env file:

ASSET_PATH="assets"

The helper functions automatically prepend this path, so you don't need to include assets/ in your calls:

// These are equivalent:
getAsset("videos/intro.mp4")
// Returns: "assets/videos/intro.mp4"

getImageAsset("logo.png")
// Returns: "assets/images/logo.png"

Changing the Base Path

If you need a different asset structure, update ASSET_PATH in your .env:

# Use a different base folder
ASSET_PATH="res"

After changing, regenerate your environment config:

metro make:env --force