我试图为用户提供一种从他们的画廊或他们的相机添加照片的方法,但是,按下按钮后,颤动不断崩溃。
我已经实现了图像选择器依赖项以及 Dart:io,迁移到了 Android X 但是,仍然没有运气。这是我的一些代码:
class _PreferencesState extends State<_Preferences>
with TickerProviderStateMixin {
File _image;
getImage(bool isCamera) async {
File image;
if (isCamera) {
image = await ImagePicker.pickImage(source: ImageSource.camera);
} else {
image = await ImagePicker.pickImage(source: ImageSource.gallery);
}
setState(() {
_image = image;
});
}
Run Code Online (Sandbox Code Playgroud)
然后在这里调用:
FlatButton(
textColor: Theme.of(context).primaryColor,
child: Text('Use Camera'),
onPressed: () {
getImage(true);
},
),
_image == null
? Container()
: Image.file(
_image,
height: 300,
width: 300,
),
Run Code Online (Sandbox Code Playgroud)
每次我调用该方法时,都会收到此错误:
发生异常。PlatformException (PlatformException(error, Attempt to invoke virtual method 'android.content.res.XmlResourceParser …
我正在用 Angular 5 编写一个应用程序。
我正在使用离子刷新器来刷新页面,如果出现错误或成功返回,我想取消微调器,因此基本上是一个 finally 块。
我需要刷新以停止旋转并在任何结果(成功或错误)中返回到默认位置。
我怎样才能用我的代码实现这一点?这是我尝试过的,但出现错误:
html
<ion-content>
<ion-refresher slot="fixed" (ionRefresh)="refresh($event)"></ion-refresher>
<div *ngIf="data">
{{ data }}
</div>
</ion-content>
Run Code Online (Sandbox Code Playgroud)
成分
export class UserInfoComponent implements OnInit {
data: any;
constructor(private userInfoService: UserInfoService) {}
ngOnInit() {
this.userInfoService
.getEmployeeInfo()
.subscribe((response) => {
this.data = response;
});
}
refresh(event) {
this.userInfoService
.getEmployeeInfo()
//.pipe(
//.finally(() => event.complete())
//)
.subscribe((response) => {
this.data = response;
event.complete(); //this works but what if there was an error
})
//.finally(() => event.complete());
//Property 'finally' does not exist …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 ionic 4 中实现 popover 并且它为我显示了这个错误,我已经为 popover 创建了一个独特的组件并且我正在页面上实现,所以我点击按钮来创建它给这个的组件错误。
我正在使用延迟加载并将模块导入文件,我做错了什么?
ERROR Error: "Uncaught (in promise): Error: No component factory found for ProfileComponent. Did you add it to @NgModule.entryComponents?
Run Code Online (Sandbox Code Playgroud)
弹出模块
ERROR Error: "Uncaught (in promise): Error: No component factory found for ProfileComponent. Did you add it to @NgModule.entryComponents?
Run Code Online (Sandbox Code Playgroud)
页面模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ProfileComponent } from './profile.component';
@NgModule({
declarations: [ProfileComponent],
imports: [
CommonModule,
],
entryComponents: [ProfileComponent],
})
export class ProfileModule { } …Run Code Online (Sandbox Code Playgroud) void main() {
MainStream.init();
runApp(
MultiProvider(
providers: [
Provider(
create: (context) => Test(context),
),
],
child: MyApp()));
}
class Test {
Test(BuildContext context) {
print("Test");
}
}
Run Code Online (Sandbox Code Playgroud)
在这个测试代码中,我希望在我的应用程序启动时打印出“Test”,但它没有。我做错了什么?我看到了像这样初始化提供程序的示例。
目前我可以使用 TCP 套接字:
final socket = await Socket.connect('127.0.0.1', 8888);
Run Code Online (Sandbox Code Playgroud)
我想使用UNIX 套接字。有没有办法用 Dart 做到这一点?
我想获得 a 中倒数第二个项目List,与 getter 类似last。
我尝试了以下操作:
final list = [1, 2, 3, 4, 5];
final secondToLast = (list..removeLast()).last; // Mutates the List
Run Code Online (Sandbox Code Playgroud)
然而它改变了List.