Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 479.5k

assets are not loading the background images on app

Mar 8 2024 5:57 PM

Hi Team

I have configured the assets, but somehow my images are not loading. I will share my path for the assets below;

 

C:\Flutter-Projects\Flutter-Furniture-Apps\kikzet_gcizman_decor\assets\icons

// yaml file
 # Add assets here
 assets:
  - assets/icons/bed-reversal.jpg
  - assets/icons/chair.jpg
  - assets/icons/comfort.jpg
  - assets/icons/decor.jpg
  - assets/icons/sofas.jpg

// main.dart
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:kikzet_gcizman_decor/screens/home.dart';



void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Decor Pty Ltd',
      theme: ThemeData(
        primarySwatch: Colors.deepPurple,
      ),
      home: const MyHomePage(title: 'Decor Store Pty Ltd'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });

  // Navigate to the selected screen
    switch(index) {
      case 0:
      Navigator.push(
        context, MaterialPageRoute(
          builder: (context)=> HomeScreen()),
          );
          break;
   }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body:CarouselSlider(
        options: CarouselOptions(
          height: 200,
          aspectRatio: 16/9,
          viewportFraction: 0.8,
          initialPage: 0,
          enableInfiniteScroll: true,
          reverse: false,
          autoPlay: true,
          autoPlayInterval: Duration(seconds: 3),
          autoPlayAnimationDuration: Duration(microseconds: 800),
          autoPlayCurve: Curves.fastOutSlowIn,
          enlargeCenterPage: true,
          scrollDirection: Axis.horizontal,
        ),
        items:[
          Image.asset('assets/icons/bed-reversal.jpg'),
        ]
        ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home, color: Colors.blue,),
            label: 'Home',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.favorite, color: Colors.green),
            label: 'Wishlist',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person, color: Colors.grey),
            label: 'Profile',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.login, color: Colors.lightGreen),
            label: 'Login',
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.blue,
        onTap: _onItemTapped,
      ),
    );
  }
}

 


Answers (2)