Home > Software design >  How to import curved nav bar appropriately?
How to import curved nav bar appropriately?

Time:06-12

I am new to Flutter. I would like to use curved navigation bar in my app, but when I run my code it shows this error.

Target of URI doesn't exist: 'package:curved_navigation_bar/home.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

Any help? Thanks a lot.

main.dart:

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/home.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
    );
  }
}

home.dart

import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  curved_navigation_bar: ^1.0.3

CodePudding user response:

When ever you wish to use any package, you need add it using command

flutter pub add curved_navigation_bar

Or by opening pubspec.yaml file and provide packageName:version under dependencies.

A better guide is to follow installation section on package.

CodePudding user response:

Check curved_navigation_bar. You have to add curved_navigation_bar: ^1.0.3 dependency in pubspec.yaml and execute flutter pub get then this import will work

Change import statement to

import 'package:curved_navigation_bar/curved_navigation_bar.dart';

CodePudding user response:

In the main.dart file you have imported home.dart with mistake. change 'package:curved_navigation_bar/home.dart' to the correct path of home.dart

import 'package:flutter/material.dart';
import 'package:curved_navigation_bar/home.dart'; //Here 

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Home(),
    );
  }
}
  • Related