如何取消/停止 Future.delayed?我读了另一个问题:如何取消 Future.delayed 函数调用,有人回答了这个可能的解决方案:https : //dart.academy/how_cancel_future/,但我不知道如何在我的代码中使用它,我不知道没有像示例那样的数据列表,我只是不希望在某些情况下执行 Future.delayed 中的代码。
await Future.delayed(Duration(seconds: myDuration)).then((_){
checkAnswer("");
jumpToNextQuestion();
});
Run Code Online (Sandbox Code Playgroud) 我有一个壁纸应用程序,它在主屏幕中显示来自 Firestore 的图片,我正在使用flutter_native_admob包来显示本机,并且广告工作正常。
我已经尝试过使用staggered_grid_view包,但它没有用,每次我将 StaggeredGridTile 中的值从 1 更改为 2 以显示原生广告而不是网格时,包都会中断,即使我设置了一个数字以在 x 张图片后显示广告,它显示在错误的地方滚动。
我需要什么:
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
final nativeAdmob = NativeAdmob();
int counter = 0;
double result;
int num = 4;
@override
Widget build(BuildContext context) {
Widget _buildGrid(int index){
return Container(
color: Colors.green,
child: Center(
child: Text("$index"),
),
);
/*
// I need to show this widget between the content
NativeAdmobBannerView(
adUnitID: "ca-app-pub-3940256099942544/2247696110", // …Run Code Online (Sandbox Code Playgroud) 我有一个墙纸应用程序,它使用 Firestore 来存储墙纸。
我想使用 Hive 来存储来自 cloud firestore 的壁纸列表,但是如何保存壁纸列表并在以后检索它?
当我尝试保存列表时,出现此错误:
E/flutter (9995): [ERROR:flutter/shell/common/shell.cc(199)] Dart 错误:未处理的异常:E/flutter (9995):HiveError:无法写入,未知类型:墙纸。您是否忘记注册适配器?
代码:
class Wallpaper extends HiveObject {
String date;
String url;
Wallpaper();
}
static Future<void> addWallpapers({@required String boxName, @required List<Wallpaper> wallpapers}) async {
var box = await Hive.openBox(boxName);
box.put(boxName, wallpapers);
print("WALLPAPER ADICIONADO NO HIVE!");
}
static Future<List<Wallpaper>> getWallpapers({@required String boxName}) async {
var box = await Hive.openBox(boxName);
List<Wallpaper> wallpapers = box.get("latest");
return wallpapers;
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序需要从小部件创建 A4 格式的图像或 pdf,实际上是一个具有动态高度的列(取决于用户在该 SingleChildScrollView -> 列上添加的内容,用户可以向该列添加图像和文本)。
如何从具有动态高度的列的小部件在 Flutter 中创建 A4 格式或 PDF 格式的图像?(我可以有一个包含适合屏幕的小部件列表和其他不适合的小部件列表的 Column,例如 20 个将走出屏幕的大小部件。)
我的第一个屏幕是登录屏幕,它需要检查用户是否已登录才能直接打开主屏幕,但是使用此检查却出现错误。
我正在检查initState,条件返回的是true,所以看起来问题出在导航器上。
如果用户已登录,跳过第一个屏幕的正确方法是什么?
错误:
I/flutter (20803): ??? EXCEPTION CAUGHT BY WIDGETS LIBRARY ????????????????????????????????????????????????????????????
I/flutter (20803): The following assertion was thrown building Navigator-[GlobalObjectKey<NavigatorState>
I/flutter (20803): _WidgetsAppState#8ce27](dirty, state: NavigatorState#db484(tickers: tracking 2 tickers)):
I/flutter (20803): 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2106 pos 12: '!_debugLocked':
I/flutter (20803): is not true.
I/flutter (20803): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (20803): more information in this error message to help you determine and fix the underlying cause.
Run Code Online (Sandbox Code Playgroud)
码: …
我有一个用 Flutter 制作的简单游戏,我可以登录用户,但我不知道如何检查用户是否已登录以及如何获取用户的数据。
对于登录,我使用这种方法,登录用户后,我可以获取他的数据:
Future<String> signInWithGoogle() async{
print("INICIALIZANDO LOGIN COM GOOGLE...");
googleSignInAccount = await googleSignIn.signIn();
googleSignInAuthentication = await googleSignInAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
AuthResult authResult = await _auth.signInWithCredential(credential);
user = authResult.user;
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
uid = user.uid;
name = user.displayName;
email = user.email;
imageUrl = user.photoUrl;
print(uid);
print(email);
print(name);
print(imageUrl);
return 'signInWithGoogle succeded: $user';
}
Run Code Online (Sandbox Code Playgroud)
对于 signOut 这个:
void signOutGoogle() async{
print("DESLOGOU!");
await googleSignIn.signOut();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试第一次使用 Google API、Google Drive API,我正在使用 Google SignIn 对用户进行身份验证。启用 Google Drive API 后,我创建了 ClientId、ClientSecret 和 Scope,但我不知道如何使用它们。我最终使用 GoogleSignInAccount 的 authHeaders 创建了一个 HTTP 客户端。
我不需要访问我的文件或管理它们,我只需要进行身份验证,因为我可能需要下载大文件,使用直接链接不起作用,因为它有一个无法扫描的大文件的确认窗口。
当我尝试使用公共文件的 ID 下载公共文件时,我总是收到以下错误。
class GoogleHttpClient extends IOClient {
Map<String, String> _headers;
GoogleHttpClient(this._headers) : super();
@override
Future<IOStreamedResponse> send(BaseRequest request) =>
super.send(request..headers.addAll(_headers));
@override
Future<Response> head(Object url, {Map<String, String> headers}) =>
super.head(url, headers: headers..addAll(_headers));
}
class GDriveHelper {
// NOT USING
//static final clientId = "??????.apps.googleusercontent.com";
//static final clientSecret = "??????";
//static final scopes = [ga.DriveApi.DriveFileScope];
static UserController userController = Get.find(); …Run Code Online (Sandbox Code Playgroud) 我有一个来自 Google Drive 的直接链接,我的应用程序将下载并显示百分比,它可以正确下载任何其他链接,但只有使用 Google Drive 直接链接,它才会显示一个很大的负数。
“Baixando”在葡萄牙语中的意思是“下载”。
await dio.download(
widget.document['url'],
path,
onReceiveProgress: (received, total){
setState(() {
progress = "Baixando..."+((received / total) * 100).toStringAsFixed(0) + "%";
});
});
Run Code Online (Sandbox Code Playgroud)
例如,使用此 Google Drive 直接链接 (pdf):https : //drive.google.com/uc?export=download&id=1N8D8lx1HlW0X99wovGEQxZRUtewN6-J2
更新:“接收”以字节为单位获取文件的大小,“总计”我只得到值:-1,尝试下载 Google Drive 直接链接时它不会改变。
我有一个应用程序需要从我的帐户播放 Google Drive 视频,我正在使用这个webview_flutter插件也尝试过flutter_webview_plugin,缩略图出现,但当我点击播放时,我收到以下错误:
String url = 'https://drive.google.com/file/d/1O8WF2MsdyoKpQZE2973IFPRpqwKUjm_q/preview';
WebView(
onWebViewCreated: (WebViewController controller){
webViewController = controller;
},
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
),
Run Code Online (Sandbox Code Playgroud)
错误:
"The deviceorientation events are blocked by feature policy. See https://github.com/WICG/feature-policy/blo
b/master/features.md#sensor-features", source: https://youtube.googleapis.com/s/player/64dddad9/player_ias.vflset/pt_BR/base.js (263)
Run Code Online (Sandbox Code Playgroud)
第二次点击播放时:
I/chromium(29212): [INFO:CONSOLE(1472)] "Uncaught (in promise) Error: Untrusted URL: https://youtube.googleapis.com/videoplayback?expire=158836583
1&ei=x1GsXtyWNuzPj-8Px_eH2Aw&ip=2804:431:c7da:c52b:854e:e83e:e7c5:eb3e&cp=QVNNWkRfVFhRQlhOOk5mQ0FhT0J5Y0k2T3ZDdjJLa0UzQVRiaHNoQlVHeXpjV3BtYW9YT2Rk
YUM&id=eb79141269cc6ad3&itag=18&source=webdrive&requiressl=yes&mh=F-&mm=32&mn=sn-bg0eznll&ms=su&mv=m&mvi=4&pl=47&ttl=transient&susc=dr&driveid=1O8
WF2MsdyoKpQZE2973IFPRpqwKUjm_q&app=explorer&mime=video/mp4&dur=2.043&lmt=1551969798109476&mt=1588351334&sparams=expire,ei,ip,cp,id,itag,source,req
uiressl,ttl,susc,driveid,app,mime,dur,lmt&sig=AOq0QJ8wRAIgEzxYGpS8RI0CRVPdZrMxdDGfkYfCezdOkiJ7iUcl5XMCIHiDsmbGel8tWT6XIU8dWdfjLJWdOlI_WHNtDNwYszU9
&lsparams=mh,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRAIgTq3W38roufwBwSPXe4fxB25kANk3s42N5x2oBvVWonoCIDaYJVrPpmNzcoU6q4bqogHP6W-Mw4p_5CRrwh59kZM4&cpn=bCev
241Hx8eXmwyo&c=WEB_EMBEDDED_PLAYER&cver=20200429", source: https://youtube.googleapis.com/s/player/64dddad9/player_ias.vflset/pt_BR/base.js (1472)
Run Code Online (Sandbox Code Playgroud) video-streaming webview html5-video android-videoview flutter
flutter ×9
dart ×6
admob ×1
flutter-hive ×1
gridview ×1
html5-video ×1
image ×1
native-ads ×1
pdf ×1
webview ×1