1

Im a newbie to flutter and working on a basic screen that will display a dice image

here is my code

import 'package:flutter/material.dart';

const startAli = Alignment.topLeft;
const endAli = Alignment.bottomRight;

class GContainer extends StatelessWidget {
  const GContainer(this.colors, {super.key});
  final List<Color> colors;
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
        colors: colors,
        begin: startAli,
        end: endAli,
      )),
      child: Center(
        child: Image.asset(
          "assets/images/dice-1.png",
          width: 150,
        ),
      ),
    );
  }
}

there are no errors showing it's simply not showing and i did add them image name to my pubspec.yaml folder

update: I ran the code on vscode chrome emulator and it does not seem to be able to find my image at all, error no image or empty

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
kawthar
  • 15
  • 5
  • go [here](https://docs.flutter.dev/ui/assets/assets-and-images) for adding images using assets add some changes in `pubspec.yaml` file – Ravindra S. Patil Aug 04 '23 at 10:56
  • 1
    thanks a lot! i found the solution instantly, it was just with indentation in my pubspec.yaml file – kawthar Aug 04 '23 at 10:58

1 Answers1

0

check this https://docs.flutter.dev/ui/assets/assets-and-images

  1. Make sure these images are available on a relevant path.
  2. add path on pubspec.yaml
  3. file then try to display image
Kasun Hasanga
  • 1,626
  • 4
  • 15
  • 35