导入包没有 working/red 下划线。 (颤振)(飞镖)
Import Packages are not working/red underline. (Flutter) (Dart)
尝试使用一些包,但由于某些原因它们没有working/I我在每个包上都有红色下划线。关于为什么会发生这种情况的任何答案?以及如果有可以提供的解决方案,将不胜感激!我是新手,还在学习中!
对于这组代码,带下划线的是
记录器包、dio 包和单位包。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:simple_gradient_text/simple_gradient_text.dart';
import '../utils/dreams_utils.dart';
class ResourcesPage extends StatefulWidget{
@override
_ResourcesPageState createState() => _ResourcesPageState();
}
class _ResourcesPageState extends State<ResourcesPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: GradientText('Sleep Resources',
style: TextStyle(fontSize: 30.0,),
colors: [colorStyle("gradient1"), colorStyle("gradient2"),
colorStyle("gradient3"), colorStyle("gradient2"),
colorStyle("gradient1")]
),
backgroundColor: colorStyle("appHeader"),
),
backgroundColor: colorStyle("appBackground"),
resizeToAvoidBottomInset: true,
body: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/SleepF.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Foundation',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepfoundation.org/sleep-hygiene/healthy-sleep-tips')
),
),
Text('We work hard to bring you the most accurate and up-to-date information about different sleep health topics. Rest assured every Sleep Foundation guide is carefully vetted and fact-checked prior to publication.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/IFFA.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('International Functional Foods Association',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://iffassociation.org/learn/how-functional-foods-may-improve-sleep-and-immune-health?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1eHFvfuovsyweVETX8I5DOztdqM_QmIN_1DjOtkDNOiKlHIn9RN1bAaAhsLEALw_wcB')
),
),
Text('We exist to ensure everyone, everywhere has an equal chance to take control of their own health and wellness. Functional foods are an important component of healthy, nutritious diets. A diet rich in functional foods promotes a healthy body, as well as a healthy mind.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/Kaiser.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Kaiser Permanente',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://healthengagement.kaiserpermanente.org/wellness-topics/sleep/')
),
),
Text('We help people reach their health goals, by listening, supporting and guiding, so they can live their best lives.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/JHM.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('John Hopkins Medical',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.hopkinsmedicine.org/health/wellness-and-prevention/sleep')
),
),
Text('At Johns Hopkins Medicine, your health and safety are our very highest priorities. We are ready to care for you and your family in our hospitals, surgery centers, and through in-person clinic and online video visits. Learn how we are keeping you safe and protected so that you can get the care you need.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/BMI.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Beautiful Mind International',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://beauty-mind.org/sleep-guru/?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1czPDb4ROkA_dhket7YAZrPB9H7AK4OqEclcbTaiU_OgDq9odhQ7x8aAhz7EALw_wcB')
),
),
Text('Beautiful Mind International project aims to educate people what is mental health, its issues, and ways to overcome them.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/CDC.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Centers for Disease Control and Prevention',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.cdc.gov/sleep/index.html')
),
),
Text('The Centers for Disease Control and Prevention is the national public health agency of the United States.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sleepnum1.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Number',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepnumber.com/categories/beds-on-sale?acid=psnonbrand&ascid=Google%2BNational-_-google-_-NB_Number_Bed-_-Number_Bed_Exact-_-516451220073-_-b-_-kwd-846217698-_-mediacode-_-Beds-_-1&key=number%20beds&s_kwcid=AL!6200!3!516451220073!b!!g!!number%20beds&k_clickid=go_cmp-193921164_adg-14393203044_ad-516451220073_kwd-846217698_dev-c_ext-_prd-&gclid=Cj0KCQiAys2MBhDOARIsAFf1D1d4C7oDgf9l_gikrEEVbK2Y7EpcHjg8AvPAmFGam3Qgjgc-XknDyYYaAtNfEALw_wcB')
),
),
Text('Sleep Number is an American manufacturer that makes the Sleep Number and Comfortaire beds, as well as foundations and bedding accessories. The company is based in Minneapolis, Minnesota. In addition to its Minnesota headquarters, Sleep Number has manufacturing and distribution facilities in South Carolina and Utah.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sunset.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('UMN Duluth Health Services',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://health-services.d.umn.edu/health-education/sleep-education-initiatives')
),
),
Text('Health Education Staff, Interns, and our previous student health advisory committee developed and administered an informal needs assessment to measure student reported barriers to sleep and methods for sleep support that students would use. We learned a lot and are putting that information into practice with a series of initiatives on campus.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
],
),
),
);
}
}
对于这组代码,红色下划线的就是
单位包、dio 包和记录器包。
import 'package:flutter/material.dart';
import 'package:units/dreams/utils/dreams_constant.dart';
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:dio/dio.dart';
import "package:units/api.dart";
List<dynamic> calculator(double hour, double minute, double sleepHour, double
sleepMinute,
UnitType uniType, UnitType unitTypeTime) {
List result = new List.filled(3, null, growable: false);
double tempHour = 0.0;
double tempMinute = 0.00;
if(uniType == UnitType.BED) {
tempHour = hour + sleepHour;
tempMinute = minute + sleepMinute;
if (tempMinute >= 60) {
tempMinute -= 60;
tempHour += 1;
}
}
if (uniType == UnitType.WAKE) {
tempHour = hour - sleepHour;
tempMinute = minute - sleepMinute;
if(tempMinute < 0){
tempMinute += 60.00;
tempHour -= 1;
}
}
if(tempHour > 12 || tempHour < 0) {
switch(unitTypeTime) {
case UnitType.AM: { unitTypeTime = UnitType.PM; }
break;
case UnitType.PM: { unitTypeTime = UnitType.AM; }
break;
default: {}
break;
}
tempHour %= 12;
}
if(tempHour ==0){
tempHour = 12;
}
//result = tempHour + (tempMinute/100);
result[0] = (tempHour + (tempMinute/100));
result[1] = unitTypeTime;
result[2] = uniType;
return result;
}
bool isEmptyString(String string){
return string == null || string.length == 0;
}
Future<int> loadValue() async{
SharedPreferences preferences = await SharedPreferences.getInstance();
int? data = preferences.getInt('data');
if( data != null ) {
return data;
} else {
return 0;
}
}
void saveValue(int value) async{
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setInt('data', value);
}
void setThemeKey(int color) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('theme', color);
}
Future<int?> getThemeKey() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final color = prefs.getInt('theme');
return color;
}
void setTheme(int theme){
switch(theme) {
case 1: { defaultTheme(); }
break;
case 2: { monochromeTheme(); }
break;
case 3: { pinkTheme(); }
break;
case 4: { sherbetTheme(); }
break;
case 5: { thunderTheme(); }
break;
case 6: { redTheme(); }
break;
case 7: { transTheme(); }
break;
case 8: { enbyTheme(); }
break;
default: { defaultTheme(); }
break;
}
}
Color mains = Colors.white60;
Color accent = Colors.cyan;
Color widgets = Colors.blueGrey.shade700;
Color gradient1 = Colors.cyan.shade900;
Color gradient2 = Colors.cyan.shade700;
Color gradient3 = Colors.cyan.shade500;
Color appHeader = Colors.blueGrey.shade900;
Color appBackground = Colors.blueGrey.shade800;
Future<int> defaultTheme() async {
mains = Colors.white60;
accent = Colors.cyan;
widgets = Colors.blueGrey.shade700;
gradient1 = Colors.cyan.shade900;
gradient2 = Colors.cyan.shade700;
gradient3 = Colors.cyan.shade500;
appHeader = Colors.blueGrey.shade900;
appBackground = Colors.blueGrey.shade800;
return 1;
}
Future<int> monochromeTheme() async {
mains = Colors.black;
accent = Colors.grey.shade700;
widgets = Colors.grey;
gradient1 = Colors.grey.shade700;
gradient2 = Colors.grey.shade500;
gradient3 = Colors.grey.shade300;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> pinkTheme() async {
mains = Colors.pink.shade500;
accent = Colors.pink;
widgets = Colors.pink.shade200;
gradient1 = Colors.pinkAccent.shade700;
gradient2 = Colors.pinkAccent.shade400;
gradient3 = Colors.pinkAccent;
appHeader = Colors.pink.shade900;
appBackground = Colors.pink.shade800;
return 1;
}
Future<int> sherbetTheme() async {
mains = Colors.deepOrange;
accent = Colors.green.shade300;
widgets = Colors.yellow.shade100;
gradient1 = Colors.purpleAccent.shade400;
gradient2 = Colors.orangeAccent.shade100;
gradient3 = Colors.cyanAccent;
appHeader = Colors.pink.shade300;
appBackground = Colors.pink.shade100;
return 1;
}
Future<int> thunderTheme() async {
mains = Colors.yellow;
accent = Colors.yellowAccent;
widgets = Colors.grey.shade700;
gradient1 = Colors.cyan.shade500;
gradient2 = Colors.yellow.shade700;
gradient3 = Colors.yellow.shade200;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> redTheme() async {
mains = Colors.red.shade900;
accent = Colors.red.shade900;
widgets = Colors.white70;
gradient1 = Colors.red.shade900;
gradient2 = Colors.red.shade700;
gradient3 = Colors.red.shade500;
appHeader = Colors.grey.shade500;
appBackground = Colors.grey.shade200;
return 1;
}
Future<int> transTheme() async {
mains = Colors.blue;
accent = Colors.pink;
widgets = Colors.white70;
gradient1 = Colors.lightBlue.shade200;
gradient2 = Colors.pinkAccent.shade100;
gradient3 = Colors.white;
appHeader = Colors.blue.shade800;
appBackground = Colors.pinkAccent.shade100;
return 1;
}
Future<int> enbyTheme() async {
mains = Colors.black;
accent = Colors.yellow.shade700;
widgets = Colors.white;
gradient1 = Colors.black;
gradient2 = Colors.yellow;
gradient3 = Colors.white;
appHeader = Colors.purple;
appBackground = Colors.purple.shade200;
return 1;
}
Color colorStyle(String color){
switch(color){
case "main":
return mains;
case "accent":
return accent;
case "widgets":
return widgets;
case "gradient1":
return gradient1;
case "gradient2":
return gradient2;
case "gradient3":
return gradient3;
case "appHeader":
return appHeader;
case "appBackground":
return appBackground;
default:
return Colors.purpleAccent;
}
}
这是我收到的错误代码
无效的 depfile: C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d
无效的 depfile:C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d
错误:无法解析 'package:logger/logger.dart' 中的包 'logger'。
错误:无法解析 'package:dio/dio.dart' 中的包 'dio'。
lib/dreams/utils/dreams_utils.dart:7:8:错误:未找到:'package:logger/logger.dart'
导入 'package:logger/logger.dart';
^
lib/dreams/utils/dreams_utils.dart:8:8:错误:未找到:'package:dio/dio.dart'
导入 'package:dio/dio.dart';
^
lib/dreams/utils/dreams_utils.dart:9:8: 错误:读取时出错 'lib/api.dart': 系统找不到指定的文件。
导入“包:units/api.dart”;
^
这是我的 pubspec.yaml
name: units
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
#
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.0.6
# 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.13.1
firebase_auth: ^3.3.11
cloud_firestore: ^3.1.10
modal_progress_hud: ^0.1.3
firebase_messaging: ^11.2.11
firebase_analytics: ^9.1.2
flutter_launcher_icons: ^0.9.2
flutter_local_notifications: ^9.4.0
#flutter_native_timezone: ^1.1.0
rxdart: ^0.27.1
#awesome_notifications: ^0.6.21
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:
- lib/assests/images/
- android/app/src/main/res/drawable/
# -lib/dreams/images/app_icon.png
# 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
运行在命令行
flutter clean
然后
flutter pub get
如果这没有帮助,请关闭并重新启动 android 工作室和文件。
如果这不能帮助从 pubspec.yaml 运行 pub get 中删除依赖项,那么 re-add 依赖项和 运行 pub get,有时你必须用锤子敲打flutter的头。
仔细检查您遇到问题的包是否确实添加到 pubspec.yaml 中,并确保它们前面没有 # infront 将它们注释掉
尝试使用一些包,但由于某些原因它们没有working/I我在每个包上都有红色下划线。关于为什么会发生这种情况的任何答案?以及如果有可以提供的解决方案,将不胜感激!我是新手,还在学习中!
对于这组代码,带下划线的是 记录器包、dio 包和单位包。
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:simple_gradient_text/simple_gradient_text.dart';
import '../utils/dreams_utils.dart';
class ResourcesPage extends StatefulWidget{
@override
_ResourcesPageState createState() => _ResourcesPageState();
}
class _ResourcesPageState extends State<ResourcesPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: GradientText('Sleep Resources',
style: TextStyle(fontSize: 30.0,),
colors: [colorStyle("gradient1"), colorStyle("gradient2"),
colorStyle("gradient3"), colorStyle("gradient2"),
colorStyle("gradient1")]
),
backgroundColor: colorStyle("appHeader"),
),
backgroundColor: colorStyle("appBackground"),
resizeToAvoidBottomInset: true,
body: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/SleepF.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Foundation',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepfoundation.org/sleep-hygiene/healthy-sleep-tips')
),
),
Text('We work hard to bring you the most accurate and up-to-date information about different sleep health topics. Rest assured every Sleep Foundation guide is carefully vetted and fact-checked prior to publication.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/IFFA.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('International Functional Foods Association',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://iffassociation.org/learn/how-functional-foods-may-improve-sleep-and-immune-health?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1eHFvfuovsyweVETX8I5DOztdqM_QmIN_1DjOtkDNOiKlHIn9RN1bAaAhsLEALw_wcB')
),
),
Text('We exist to ensure everyone, everywhere has an equal chance to take control of their own health and wellness. Functional foods are an important component of healthy, nutritious diets. A diet rich in functional foods promotes a healthy body, as well as a healthy mind.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/Kaiser.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Kaiser Permanente',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://healthengagement.kaiserpermanente.org/wellness-topics/sleep/')
),
),
Text('We help people reach their health goals, by listening, supporting and guiding, so they can live their best lives.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/JHM.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('John Hopkins Medical',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.hopkinsmedicine.org/health/wellness-and-prevention/sleep')
),
),
Text('At Johns Hopkins Medicine, your health and safety are our very highest priorities. We are ready to care for you and your family in our hospitals, surgery centers, and through in-person clinic and online video visits. Learn how we are keeping you safe and protected so that you can get the care you need.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/BMI.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Beautiful Mind International',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://beauty-mind.org/sleep-guru/?gclid=Cj0KCQiAys2MBhDOARIsAFf1D1czPDb4ROkA_dhket7YAZrPB9H7AK4OqEclcbTaiU_OgDq9odhQ7x8aAhz7EALw_wcB')
),
),
Text('Beautiful Mind International project aims to educate people what is mental health, its issues, and ways to overcome them.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/CDC.png",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Centers for Disease Control and Prevention',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.cdc.gov/sleep/index.html')
),
),
Text('The Centers for Disease Control and Prevention is the national public health agency of the United States.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sleepnum1.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('Sleep Number',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://www.sleepnumber.com/categories/beds-on-sale?acid=psnonbrand&ascid=Google%2BNational-_-google-_-NB_Number_Bed-_-Number_Bed_Exact-_-516451220073-_-b-_-kwd-846217698-_-mediacode-_-Beds-_-1&key=number%20beds&s_kwcid=AL!6200!3!516451220073!b!!g!!number%20beds&k_clickid=go_cmp-193921164_adg-14393203044_ad-516451220073_kwd-846217698_dev-c_ext-_prd-&gclid=Cj0KCQiAys2MBhDOARIsAFf1D1d4C7oDgf9l_gikrEEVbK2Y7EpcHjg8AvPAmFGam3Qgjgc-XknDyYYaAtNfEALw_wcB')
),
),
Text('Sleep Number is an American manufacturer that makes the Sleep Number and Comfortaire beds, as well as foundations and bedding accessories. The company is based in Minneapolis, Minnesota. In addition to its Minnesota headquarters, Sleep Number has manufacturing and distribution facilities in South Carolina and Utah.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
new Container(
margin: EdgeInsets.all(30.0),
child: new Card(
color: Colors.transparent,
elevation: 400.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Image.asset("assets/images/sunset.jpeg",
height: 400,
width: 400,
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: new InkWell(
child: new Text('UMN Duluth Health Services',
style: TextStyle(
color: colorStyle("main"),
fontWeight: FontWeight.bold,
fontSize: 20.0),
),
onTap: () => launch('https://health-services.d.umn.edu/health-education/sleep-education-initiatives')
),
),
Text('Health Education Staff, Interns, and our previous student health advisory committee developed and administered an informal needs assessment to measure student reported barriers to sleep and methods for sleep support that students would use. We learned a lot and are putting that information into practice with a series of initiatives on campus.',
style: TextStyle(
color: colorStyle("main"),
fontSize: 15.0),
),
],
),
),
),
],
),
),
);
}
}
对于这组代码,红色下划线的就是 单位包、dio 包和记录器包。
import 'package:flutter/material.dart';
import 'package:units/dreams/utils/dreams_constant.dart';
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:dio/dio.dart';
import "package:units/api.dart";
List<dynamic> calculator(double hour, double minute, double sleepHour, double
sleepMinute,
UnitType uniType, UnitType unitTypeTime) {
List result = new List.filled(3, null, growable: false);
double tempHour = 0.0;
double tempMinute = 0.00;
if(uniType == UnitType.BED) {
tempHour = hour + sleepHour;
tempMinute = minute + sleepMinute;
if (tempMinute >= 60) {
tempMinute -= 60;
tempHour += 1;
}
}
if (uniType == UnitType.WAKE) {
tempHour = hour - sleepHour;
tempMinute = minute - sleepMinute;
if(tempMinute < 0){
tempMinute += 60.00;
tempHour -= 1;
}
}
if(tempHour > 12 || tempHour < 0) {
switch(unitTypeTime) {
case UnitType.AM: { unitTypeTime = UnitType.PM; }
break;
case UnitType.PM: { unitTypeTime = UnitType.AM; }
break;
default: {}
break;
}
tempHour %= 12;
}
if(tempHour ==0){
tempHour = 12;
}
//result = tempHour + (tempMinute/100);
result[0] = (tempHour + (tempMinute/100));
result[1] = unitTypeTime;
result[2] = uniType;
return result;
}
bool isEmptyString(String string){
return string == null || string.length == 0;
}
Future<int> loadValue() async{
SharedPreferences preferences = await SharedPreferences.getInstance();
int? data = preferences.getInt('data');
if( data != null ) {
return data;
} else {
return 0;
}
}
void saveValue(int value) async{
SharedPreferences preferences = await SharedPreferences.getInstance();
preferences.setInt('data', value);
}
void setThemeKey(int color) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('theme', color);
}
Future<int?> getThemeKey() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final color = prefs.getInt('theme');
return color;
}
void setTheme(int theme){
switch(theme) {
case 1: { defaultTheme(); }
break;
case 2: { monochromeTheme(); }
break;
case 3: { pinkTheme(); }
break;
case 4: { sherbetTheme(); }
break;
case 5: { thunderTheme(); }
break;
case 6: { redTheme(); }
break;
case 7: { transTheme(); }
break;
case 8: { enbyTheme(); }
break;
default: { defaultTheme(); }
break;
}
}
Color mains = Colors.white60;
Color accent = Colors.cyan;
Color widgets = Colors.blueGrey.shade700;
Color gradient1 = Colors.cyan.shade900;
Color gradient2 = Colors.cyan.shade700;
Color gradient3 = Colors.cyan.shade500;
Color appHeader = Colors.blueGrey.shade900;
Color appBackground = Colors.blueGrey.shade800;
Future<int> defaultTheme() async {
mains = Colors.white60;
accent = Colors.cyan;
widgets = Colors.blueGrey.shade700;
gradient1 = Colors.cyan.shade900;
gradient2 = Colors.cyan.shade700;
gradient3 = Colors.cyan.shade500;
appHeader = Colors.blueGrey.shade900;
appBackground = Colors.blueGrey.shade800;
return 1;
}
Future<int> monochromeTheme() async {
mains = Colors.black;
accent = Colors.grey.shade700;
widgets = Colors.grey;
gradient1 = Colors.grey.shade700;
gradient2 = Colors.grey.shade500;
gradient3 = Colors.grey.shade300;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> pinkTheme() async {
mains = Colors.pink.shade500;
accent = Colors.pink;
widgets = Colors.pink.shade200;
gradient1 = Colors.pinkAccent.shade700;
gradient2 = Colors.pinkAccent.shade400;
gradient3 = Colors.pinkAccent;
appHeader = Colors.pink.shade900;
appBackground = Colors.pink.shade800;
return 1;
}
Future<int> sherbetTheme() async {
mains = Colors.deepOrange;
accent = Colors.green.shade300;
widgets = Colors.yellow.shade100;
gradient1 = Colors.purpleAccent.shade400;
gradient2 = Colors.orangeAccent.shade100;
gradient3 = Colors.cyanAccent;
appHeader = Colors.pink.shade300;
appBackground = Colors.pink.shade100;
return 1;
}
Future<int> thunderTheme() async {
mains = Colors.yellow;
accent = Colors.yellowAccent;
widgets = Colors.grey.shade700;
gradient1 = Colors.cyan.shade500;
gradient2 = Colors.yellow.shade700;
gradient3 = Colors.yellow.shade200;
appHeader = Colors.grey.shade900;
appBackground = Colors.grey.shade800;
return 1;
}
Future<int> redTheme() async {
mains = Colors.red.shade900;
accent = Colors.red.shade900;
widgets = Colors.white70;
gradient1 = Colors.red.shade900;
gradient2 = Colors.red.shade700;
gradient3 = Colors.red.shade500;
appHeader = Colors.grey.shade500;
appBackground = Colors.grey.shade200;
return 1;
}
Future<int> transTheme() async {
mains = Colors.blue;
accent = Colors.pink;
widgets = Colors.white70;
gradient1 = Colors.lightBlue.shade200;
gradient2 = Colors.pinkAccent.shade100;
gradient3 = Colors.white;
appHeader = Colors.blue.shade800;
appBackground = Colors.pinkAccent.shade100;
return 1;
}
Future<int> enbyTheme() async {
mains = Colors.black;
accent = Colors.yellow.shade700;
widgets = Colors.white;
gradient1 = Colors.black;
gradient2 = Colors.yellow;
gradient3 = Colors.white;
appHeader = Colors.purple;
appBackground = Colors.purple.shade200;
return 1;
}
Color colorStyle(String color){
switch(color){
case "main":
return mains;
case "accent":
return accent;
case "widgets":
return widgets;
case "gradient1":
return gradient1;
case "gradient2":
return gradient2;
case "gradient3":
return gradient3;
case "appHeader":
return appHeader;
case "appBackground":
return appBackground;
default:
return Colors.purpleAccent;
}
}
这是我收到的错误代码
无效的 depfile: C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d 无效的 depfile:C:\Users\Mahjur - Coding\Desktop\SweetDreams-X.2.dart_tool\flutter_build\e98d11342ddd14555bbca12c2fd83e4a\kernel_snapshot.d 错误:无法解析 'package:logger/logger.dart' 中的包 'logger'。 错误:无法解析 'package:dio/dio.dart' 中的包 'dio'。 lib/dreams/utils/dreams_utils.dart:7:8:错误:未找到:'package:logger/logger.dart' 导入 'package:logger/logger.dart'; ^ lib/dreams/utils/dreams_utils.dart:8:8:错误:未找到:'package:dio/dio.dart' 导入 'package:dio/dio.dart'; ^ lib/dreams/utils/dreams_utils.dart:9:8: 错误:读取时出错 'lib/api.dart': 系统找不到指定的文件。
导入“包:units/api.dart”; ^
这是我的 pubspec.yaml
name: units
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
#
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.0.6
# 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.13.1
firebase_auth: ^3.3.11
cloud_firestore: ^3.1.10
modal_progress_hud: ^0.1.3
firebase_messaging: ^11.2.11
firebase_analytics: ^9.1.2
flutter_launcher_icons: ^0.9.2
flutter_local_notifications: ^9.4.0
#flutter_native_timezone: ^1.1.0
rxdart: ^0.27.1
#awesome_notifications: ^0.6.21
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:
- lib/assests/images/
- android/app/src/main/res/drawable/
# -lib/dreams/images/app_icon.png
# 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
运行在命令行
flutter clean
然后
flutter pub get
如果这没有帮助,请关闭并重新启动 android 工作室和文件。
如果这不能帮助从 pubspec.yaml 运行 pub get 中删除依赖项,那么 re-add 依赖项和 运行 pub get,有时你必须用锤子敲打flutter的头。
仔细检查您遇到问题的包是否确实添加到 pubspec.yaml 中,并确保它们前面没有 # infront 将它们注释掉