I created a flutter project and when I tried to add an icon using icons.[icon here] it didn't show up even though uses-material-design: true in the pubspec
Code of Icon
import 'package:flutter/material.dart';
import 'package:search_choices/search_choices.dart';
class DonateFood extends StatefulWidget {
const DonateFood({Key? key}) : super(key: key);
#override
_DonorOtherState createState() => _DonorOtherState();
}
class _DonorOtherState extends State<DonateFood> {
#override
Widget build(BuildContext context) {
String dropdownValue = 'Food Type';
return Scaffold(
body: Container(
child: const Center(
child: Icon(
Icons.six_mp_sharp,
size: 100,
),
),
),
);
}
}
Pubspec.yaml
name: feedme
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: "^1.10.0"
firebase_performance: "^0.7.1"
firebase_database: ^7.2.1
firebase_auth: ^3.0.1
font_awesome_flutter: ^9.1.0
flutter_facebook_auth: ^3.5.0+1
google_sign_in: ^5.0.0
cloud_firestore: ^2.4.0
google_fonts: ^2.1.0
flutter_neumorphic: ^3.1.0
auto_size_text: ^3.0.0-nullsafety.0
splashscreen: ^1.3.5
flutter_google_places: ^0.3.0
places_service: ^0.1.0+2
provider: ^6.0.1
http: ^0.13.3
geolocator: ^7.7.1
google_maps_flutter: ^2.0.9
top_snackbar_flutter: ^1.0.2
firebase_storage: ^10.1.0
search_choices: ^2.0.14
dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
uses-material-design: true
fonts:
- family: rHeavy
fonts:
- asset: Fonts/SF-Pro-Rounded-Heavy.otf
- family: rRegular
fonts:
- asset: Fonts/SF-Pro-Rounded-Regular.otf
- family: rBold
fonts:
- asset: Fonts/SF-Pro-Rounded-Bold.otf
- family: rLight
fonts:
- asset: Fonts/SF-Pro-Rounded-Light.otf
- family: rSemibold
fonts:
- asset: Fonts/SF-Pro-Rounded-Semibold.otf
- family: tMedium
fonts:
- asset: Fonts/SF-Pro-Text-Medium.otf
- family: tSemibold
fonts:
- asset: Fonts/SF-Pro-Text-Semibold.otf
- family: tRegular
fonts:
- asset: Fonts/SF-Pro-Text-Regular.otf
- family: dMedium
fonts:
- asset: Fonts/SF-Pro-Display-Medium.otf
assets:
- Images/
Related
I would like to ask for help, I've searched all the answers here in the community and I can't solve my error.
I had to update a personal project to Android sdk 32, but when I try to run the Flutter pub get command I'm having an SDK version error, I'm leaving the pub spec and the error image below.
Error Picture Here
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.17.0 <3.0.0"
dependencies:
dio: ^4.0.0
rxdart: ^0.27.1
bloc_pattern: ^3.0.0
flutter_launcher_icons: ^0.10.0
flutter_translate: ^4.0.3
flutter_localizations:
sdk: flutter
equatable: any
json_annotation: any
freezed_annotation: any
webview_flutter: ^3.0.4
flutter_cache_manager: ^3.3.0
upgrader: ^4.6.1
video_thumbnail: ^0.5.3
## Animation rive
#rive: ^0.7.22
# Native
package_info_plus: ^1.0.3
geolocator: ^9.0.2
path_provider: ^2.0.2
file_picker: ^4.1.6
open_file: ^3.2.1
url_launcher: ^6.0.8
shared_preferences: ^2.0.6
qr_code_scanner: ^1.0.1
cross_file: ^0.3.2
camera: ^0.10.0+3
# Layout
introduction_screen: ^3.0.2
font_awesome_flutter: ^10.1.0
select_form_field: "^2.1.0"
#mask_text_input_formatter: ^2.0.0
another_flushbar: ^1.10.24
flutter_switch: ^0.3.2
flutter_app_badger: ^1.2.0
image_picker: ^0.8.5+3
flutter_neat_and_clean_calendar: ^0.3.8+22
date_utils: ^0.2.0
date_format: ^2.0.2
#flutter_form_builder: ^6.0.1
date_time_picker: ^2.1.0
flutter_rating_bar: ^4.0.0
signature: ^5.2.1
flutter_simple_treeview: ^3.0.0-nullsafety.1
widget_to_image: ^2.0.0
flutter_email_sender: ^5.0.2
in_app_review: ^2.0.2
flutter_typeahead: ^4.1.1
brasil_fields: ^1.5.0
grouped_list: ^5.1.2
mat_month_picker_dialog: ^1.0.1
# Videos Acesso Cameras
video_viewer: ^1.2.6
fijkplayer: ^0.10.1
# Conteudo html
flutter_html: ^3.0.0-alpha.5
## FIREBASE
firebase_core: ^1.13.1
firebase_messaging: ^13.0.3
flutter_local_notifications: ^11.0.1
## Share Social
share: ^2.0.4
flutter:
sdk: flutter
json_serializable: any
build_runner: any
freezed: any
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
dev_dependencies:
mockito: ^5.0.10
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
flutter_icons:
android: "ic_launcher"
ios: true
image_path: "assets/icon/icon.png"
adaptive_icon_background: "assets/icon/icon.png"
adaptive_icon_foreground: "assets/icon/icon.png"
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/img/
- assets/i18n/
- assets/animation/loading.riv
- assets/json/paises.json
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages```
replace your sdk with
sdk: ">=2.15.1 <3.0.0"
I managed to solve this problem, I uninstalled flutter on the mac and installed it again, I think the mac was cached.
I'm using the flutter camera plugin to record a video but the code keeps throwing:
The method '[]' was called on null.
Receiver: null
Tried calling: [](0)
when I try to get the first camera (cameras.first or cameras[0]). This is happening even with the examples given in the plugin docs: https://pub.dev/packages/camera/example
Here's my pubspec.yaml:
# #format
name: camera_example
description: A camera example app
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
archive: ^3.1.2
bloc: ^7.0.0
cached_network_image: ^3.1.0
cupertino_icons: ^1.0.3
dio: null
equatable: ^2.0.3
eva_icons_flutter: ^3.0.0
flutter:
sdk: flutter
flutter_bloc: ^7.1.0
flutter_secure_storage: ^4.2.1
flutter_svg: ^0.22.0
font_awesome_flutter: ^8.8.1
http: ^0.13.3
image_picker: ^0.8.2
introduction_screen: ^2.1.0
line_icons: null
logger: null
path_provider: ^2.0.2
provider: ^5.0.0
rxdart: ^0.27.1
shared_preferences: ^2.0.6
video_player: ^2.1.10
camera:
# path: ./
carousel_slider: ^4.0.0
marquee: ^2.2.0
responsive_builder: ^0.4.1
page_indicator: ^0.4.1
path: ^1.8.0
permission_handler:
dev_dependencies:
flutter_launcher_icons: ^0.9.0
flutter_native_splash: ^1.2.0
flutter_native_splash:
color: "#000000"
image: "assets/images/bg.png"
android: true
ios: true
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/images/icon.png"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/videos/
- assets/
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: TikTokIcons
fonts:
- asset: assets/fonts/TikTokIcons.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
I believe I have done everything according to the documentation but I keep on getting the error. I am testing on a real android(android 10) device.
The example code I'm referring to:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
List<CameraDescription> cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
runApp(CameraApp());
}
class CameraApp extends StatefulWidget {
#override
_CameraAppState createState() => _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
CameraController controller;
#override
void initState() {
super.initState();
controller = CameraController(cameras[0], ResolutionPreset.max);
controller.initialize().then((_) {
if (!mounted) {
return;
}
setState(() {});
});
}
#override
void dispose() {
controller?.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
if (!controller.value.isInitialized) {
return Container();
}
return MaterialApp(
home: CameraPreview(controller),
);
}
}
PS: I'm new to flutter
This is my pubspec.yaml
Working dir: C:\Users\kom.13\AndroidStudioProjects\flutter_app1
C:\src\flutter\flutter\bin\cache\dart-sdk\bin\pub.bat get
Error on line 22, column 2 of pubspec.yaml: Expected a key while parsing a block mapping.
â•·
22 │ fonts:
│ ^
╵
Process finished with exit code 65
name: flutter_app1
description: A new Flutter application.
publish_to:
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: Pacifico
fonts:
- asset: fonts/Pacifico-Regular.ttf
so, you have an indentation issue in the fonts sections. Do this instead:
name: flutter_app1
description: A new Flutter application.
publish_to:
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: Pacifico
fonts:
- asset: fonts/Pacifico-Regular.ttf
For reference, check this page: https://flutter.dev/docs/cookbook/design/fonts
I think You have an Error of indentation of which means your fonts are not at the correct position, see mine below code.
fonts:
- family: GraphikWide
fonts:
- asset: fonts/Graphik-Wide-Regular.otf
- asset: fonts/Graphik-Wide-Medium.otf
weight: 400
- family: Gibson
fonts:
- asset: fonts/gibson-regular.ttf
- asset: fonts/gibson-semibold.ttf
weight: 400
- asset: fonts/gibson-light.ttf
weight: 100
just replace your full font code in pubspec with my code then do the changes
I am trying to load an image but i keep getting this error Exception has occurred.
FlutterError (Unable to load asset: assests/1.png),
this is what have tried so far, the image is located in my assets folder in my root directory
name: wallet_app
description: A new Flutter application.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0
provider: ^3.0.0+1
email_validator: ^1.0.0
bubble_bottom_bar: ^1.2.0
fluttertoast: ^7.0.1
flutter_icons : 1.1.0
flutter_spinkit: "^4.1.2"
firebase_core : ^0.5.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
assets:
- assets/1.png
- assets/newdp.png
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
and this is how i implement it
return Container(
margin: EdgeInsets.only(top: 80),
child: Column(
children: <Widget>[
Center(
child: Image.asset(
"assests/1.png",
width: 600.0,
height: 240.0,
fit: BoxFit.cover,
),),
Center( child:Text("Hello tlululuhere"))]));
........................................................................................................................................................................................................
youre getting the wrong path:
Image.asset(
"assests/1.png",
must be :
Image.asset(
"assets/1.png",
So following this tutorial for a simple login UI in Flutter
https://medium.com/better-programming/simple-firebase-login-flow-in-flutter-6f44c2b5c58a
Apparently this package in flutter isn't being imported correctly. The particular lines that are not working are these 3 lines of code
import 'package:provider/provider.dart';
ChangeNotifierProvider<AuthService>( //TODO: authservices and provider pages
future: Provider.of<AuthService>(context).getUser(),
I have been searching a bunch and tried reading the docs and couldn't get any easy answers, but anyway thank you to anyone who gets me the answer to this
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'home_page.dart';
import 'auth.dart';
import 'login_page.dart';
void main() => runApp(
ChangeNotifierProvider<AuthService>( //TODO: authservices and provider pages
child: MyApp(),
builder: (BuildContext context) {
return AuthService();
},
),
);
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: FutureBuilder(
future: Provider.of<AuthService>(context).getUser(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return snapshot.hasData ? HomePage() : LoginPage();
} else {
return Container(color: Colors.white);
}
},
),
);
}
}
the pubspec.yaml file for anyone looking
name: login_flutter_app
description: A new Flutter application.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Had to put these into the project
cupertino_icons: ^0.1.2
flutter_blue: ^0.6.3+1
provider: ^4.0.4
Just add dependency provider: ^4.1.1 in pubspec.yaml file. it looks like bellow
dependencies:
flutter:
sdk: flutter
provider: ^4.1.1