How can I import example project inside of pub-get packages in flutter - flutter

Some of pub-get packages have example project inside of the project.
and I search for how to import example project.
most of answer is add path:../
but that doesn't work for me
camerawesome:
path: ../
makes error : Can't find the pubspec.yaml file in /Users/user_name/workspace/flutter-workspace
How can I import example project
flutter create example and copy the source is the only way?
example source looks like import using underbar directory, this is also not make sense for me.
import 'package:camerawesome_example/widgets/top_bar.dart';
Thanks for read my question !!

you want import example code to your project, just like a third lib ?
the example project not real part of lib. you cant just import the code to
your code for use. it's not design for that. it's just show how to use lib.

Related

Target of URI doesn't exist: 'theme.dart', 'colors.dart', 'ink_well.dart', etc

Currently trying to run an example of a guitar tuner created with the 'flutter_fft' plugin, however, I'm receiving an error on some of my imports. I can see that all of these files exist inside my flutter folder but can't seem to access them?
Here are my imports and the error I am receivingmy imports and the error I am receiving
But as you can see in this screenshot I do have all of those files available somewhere on my PC, and the material.dart import works fine?
I've been trying to work this out for a while but after asking a question here the other day and getting an almost immediate, and extremely helpful response, I've decided to come here again. Thanks in advance.
When importing from a package (like flutter) you must first specify the package with a package: and then the path to the imports.
If you don't specify this, dart will assume you are trying to import a file on the same directory as the current file.
so instead of import 'button_style.dart'; it should be import package:flutter/src/material/button_style.dart.
The above will work, but I will let you know that the sole purpose of importing package:flutter/material.dart; is to automatically import every file inside the material directory, and so, all of your imports are useless if you already import material.dart.

How to import all Dart files from a Directory?

I am new to dart so please bear with me if this is really bad question. I am developing an app using flutter, and I have one question. I have many screens in my app, like About the App, Homepage, Upcoming Events, etc. I have kept all these screens in a folder in lib/screens directory. And to import them in main.dart for routes I have to import each and every file, like
import "screens/homepage.dart";
import "screens/aboutTheApp.dart";
import "screens/upcomingEvents.dart";
Is there a simpler way to do it? Is there a way to import the "screens" directory at once?
I have tried to import the complete folder and tried making it a package, but it isn't helping.
You can create a file in the screens directory and call it all.dart or whatever you like. In this file, you will simply export all of the Dart files in that folder:
export 'homepage.dart';
export 'aboutTheApp.dart';
export 'upcomingEvents.dart';
Now, whenever you want to use any file from that folder, you can just import all.dart or what you called it:
import 'screens/all.dart`;
...
Other than that, there is no possibility to import a directory.
No, there is no simpler way.
Dart do not offer a directory import.
No, there is no direct way to automatically include all .dart files from a directory. You should be able to use some form of code generation (e.g. with source_gen or build) to generate a .dart file at build-time that other files could import.
I create a package to auto export all dart files.
I named it auto_exporter you can search it on https://pub.dev/packages
when you are creating a dart package I think it's useful.

Umbrella Imports with Dart/Flutter

I am developing a plugin for Dart (Flutter). I have split up the source into many different implementation files to keep things clean and avoid having one massive file.
The problem is, I don't want users to have to import tons of source files whenever they want to use my package.
Is there any way, in flutter or Dart itself, to be able to declare some sort of umbrella interface?
In your plugin, you have a lib folder. Create a lib/src sub-folder and move the bulk of your implementation files there. It's typical to be left with just one file in lib e.g. someplugin.dart.
In there you can have any top level classes or functions but this is where you include the implementation source files using the export directive.
Here's an example from the google_sign_in plugin, from google_sign_in.dart:
import 'dart:async';
import 'dart:ui' show hashValues;
import 'package:flutter/services.dart' show MethodChannel;
import 'package:meta/meta.dart' show visibleForTesting;
import 'src/common.dart'; // this import is only required if used by some top level
// class lower down this file
export 'src/common.dart'; // this export means that your plugin's users don't need
// to import it themselves

How to import local files in Go?

I would like to organize my Go code into smaller chunks. Lets assume I am writing a web application that follows the MVC pattern. I would like to organize my code like this:
main.go
controllers/whatever/whatever.go
models/whateverelse/whateverelse.go
And than in main.go I would like to:
import "controllers/whatever"
Is this possible with Go? It seems the only option, that does not make too much sense is to put the the files into the GOPATH/src folder. In that case I need to set the git repository to track the $GOPATH/ instead of just tracking my project that is $GOPATH/src/github/username/project.
The solution you have could definitely work if you have the standard github directory structure. However, I would like to point out that to import a go library, you just need to specify the path to that library starting from the directory below src.
If your project library has the path:
src/yourproject1/controllers
and your main code has the path:
src/yourproject2/main.go
In main.go, you simply need to say:
import "yourproject1/controllers"
The solution came from IRC thanks to jaw22:
import "github.com/yoursuername/yourproject/yourlib"

how to add JSON framework

Goal : Add the latest JSON into my project.
I download JSON from this link https://github.com/stig/json-framework/downloads and drag the folder name stig-json-framework-a23638b in my project. and Check “Copy items into destination group’s folder (if needed)”.
stig-json-framework-a23638b folder shows many sub folder inside like Classes, Examples, SBJSON, sbjson-ios, sbjson-iosTests.
after that when I #import "JSON.h" it gives error JSON.h file not found.
I know I am doing wrong please direct me in right direction. and provide me link from where I download JSON Framework. and any good tutorial links.
many thanks.
You dont need to import the whole project with examples and target of it.Just import whatever in the "classes" folder in that framework..
https://github.com/stig/json-framework/tree/master/src/main/objc
Files listed in above link is enough to import framework.
As #sanchitsingh said, you need to import only "SBJSON.h".
There is no file JSON.h.
Try this
#import "SBJson.h"