Horje
flutter image asset Code Example
flutter image asset
// pubspec.yaml
flutter:
  assets:
    - graphics/

// Inside your widget
Image(image: AssetImage('graphics/background.png'))
Source: flutter.dev
image from assets in flutter
Widget build(BuildContext context) {
  return Image(image: AssetImage('graphics/background.png'));
}
Source: flutter.dev
flutter get image file from assets
import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart' show rootBundle;
import 'package:path_provider/path_provider.dart';

Future<File> getImageFileFromAssets(String path) async {
  final byteData = await rootBundle.load('assets/$path');

  final file = File('${(await getTemporaryDirectory()).path}/$path');
  await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

  return file;
}

File f = await getImageFileFromAssets('images/myImage.jpg');
asset image in flutter
*Note:-
     Very important thing to note while using asset is that:
--> In "pubspec.yaml" file:-
	line with code "uses-material-design: true"
    and line with code "  assets:"
    should lie in same column 
    
--> example:-
  # the material Icons class.
  uses-material-design: true    //this line

  # To add assets to your application, add an assets section, like this:
  assets:                      // and this line (in same column)
     - assets/
--> Don't be oversmart and give your image name too in assets like this:-
  "  assets:
     - assets/onePiece"
     This will cause error....(Believe it)....




5

Related
string to double dart Code Example string to double dart Code Example
flutter text color Code Example flutter text color Code Example
screen size flutter Code Example screen size flutter Code Example
flutter get width of screen Code Example flutter get width of screen Code Example
round border container flutter Code Example round border container flutter Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10