Skip to content

TypeScript code snippet – How to load image from asssets in flutter?

// Edit pubspec.yaml file
flutter:
    assets:
      - assets/images/

// in class_name.dart file get image like this
        
  import 'package:flutter/material.dart';

  void main() => runApp(MyApp());

  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text("Image from assets"),
          ),
          body: Image.asset('assets/images/lake.jpg'), //   <--- image
        ),
      );
    }
  }
See also  Java code snippet - How to generate guid?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.