Android 为什么Flatter导入提供程序包不工作?
因此,请遵循本教程,在Flatter中创建一个简单的登录UI 很明显,这个颤振包装没有正确进口。不起作用的特定行是这3行代码Android 为什么Flatter导入提供程序包不工作?,android,ios,flutter,dart,mobile,Android,Ios,Flutter,Dart,Mobile,因此,请遵循本教程,在Flatter中创建一个简单的登录UI 很明显,这个颤振包装没有正确进口。不起作用的特定行是这3行代码 import 'package:provider/provider.dart'; ChangeNotifierProvider<AuthService>( //TODO: authservices and provider pages future: Provider.of<AuthService>(context).getUser(), 导入
import 'package:provider/provider.dart';
ChangeNotifierProvider<AuthService>( //TODO: authservices and provider pages
future: Provider.of<AuthService>(context).getUser(),
导入“包:provider/provider.dart”;
ChangeNotifierProvider(//TODO:authservices和提供程序页
future:Provider.of(context.getUser(),
我一直在搜索一堆文件,并试图阅读这些文件,但无法得到任何简单的答案,但无论如何,感谢所有给我答案的人
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);
}
},
),
);
}
}
导入“包装:颤振/材料.省道”;
导入“包:provider/provider.dart”;
导入“主页.省道”;
导入“auth.dart”;
导入“login_page.dart”;
void main()=>runApp(
ChangeNotifierProvider(//TODO:authservices和提供程序页
子项:MyApp(),
生成器:(BuildContext上下文){
返回AuthService();
},
),
);
类MyApp扩展了无状态小部件{
//此小部件是应用程序的根。
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(原始样本:颜色。蓝色),
家:未来建设者(
future:Provider.of(context.getUser(),
生成器:(上下文,异步快照){
if(snapshot.connectionState==connectionState.done){
返回snapshot.hasData?主页():LoginPage();
}否则{
返回容器(颜色:颜色.白色);
}
},
),
);
}
}
pubspec.yaml文件供任何人查看
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
name:login\u flatter\u应用程序
描述:一个新的颤振应用。
#下面定义了应用程序的版本和内部版本号。
#版本号是由点分隔的三个数字,如1.2.43
#后跟可选的内部版本号,以+分隔。
#版本和制造商编号都可能在颤振中被覆盖
#通过分别指定--build name和--build number来生成。
#在Android中,版本名用作版本名,而版本号用作版本代码。
#更多关于Android版本控制的信息,请访问https://developer.android.com/studio/publish/versioning
#在iOS中,生成名称用作CbundleShortVersionString,而生成编号用作CbundLeverVersion。
#阅读有关iOS版本控制的更多信息,请访问
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
版本:1.0.0+1
环境:
sdk:“>=2.1.0必须将这些应用到项目中
cupertino_图标:^0.1.2
颤振蓝色:^0.6.3+1
提供程序:^4.0.4
必须把这些投入到项目中
cupertino_图标:^0.1.2
颤振蓝色:^0.6.3+1
提供程序:^4.0.4
只需将依赖项提供程序:^4.1.1添加到pubspec.yaml文件中。它看起来像下面这样
dependencies:
flutter:
sdk: flutter
provider: ^4.1.1
只需将依赖项提供程序:^4.1.1添加到pubspec.yaml文件中。它看起来像下面这样
dependencies:
flutter:
sdk: flutter
provider: ^4.1.1
您的pubspec.yaml
看起来像什么?名称:登录\u flatter\u应用程序描述:一个新的flatter应用程序。版本:1.0.0+1环境:sdk::>=2.1.0我删除了大部分评论,但这就是它看起来的样子。你需要在你的pubspec.yaml依赖项中包含提供者。你的pubspec.yaml
看起来像什么?name:login\u flatter\u应用程序描述:一个新的flatter应用程序。版本:1.0.0+1环境:sdk:“>=2.1.0我删除了大部分注释,但这就是您需要在pubspec.yaml依赖项中包含提供者的情况