我注意到我的项目中出现了新的 lint 问题。
长话短说:
我需要在我的自定义类中使用 BuildContext
flutter lint 工具与 aysnc 方法一起使用时并不满意。
例子:
MyCustomClass{
final buildContext context;
const MyCustomClass({required this.context});
myAsyncMethod() async {
await someFuture();
# if (!mounted) return; << has no effect even if i pass state to constructor
Navigator.of(context).pop(); # << example
}
}
Run Code Online (Sandbox Code Playgroud) dart flutter flutter-dependencies flutter-state flutter-build
为什么ValueError: malformed node or string当我将以下格式的数据传递到“parse_webhook”函数时会收到此错误消息?
谢谢!
webhook_data = {"side": "BUY","key": "8234023409fa3242309sdfasdf903024917325"}
def parse_webhook(webhook_data):
"""
:param webhook_data: POST data from tradingview, as a string.
:return: Dictionary version of string.
"""
data = ast.literal_eval(webhook_data)
return data
Run Code Online (Sandbox Code Playgroud)
我得到错误:
File "C:\Users\User\anaconda3\lib\ast.py", line 55, in _convert_num
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: {'side': 'BUY', 'key': '8234023409fa3242309sdfasdf903024917325'}
Run Code Online (Sandbox Code Playgroud) 我正在使用web (Chrome)来运行我的应用程序。但是,我收到错误。这是错误:
\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY WIDGETS LIBRARY \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nThe following assertion was thrown building Builder:\nAssertion failed:\nfile:///Users/name/development/flutter/packages/flutter/lib/src/foundation/stack_frame.dart:192:7\nline != \'===== asynchronous gap ===========================\'\n"Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen\nif FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack\ntraces to the framework, such as during tests."\n\nThe relevant error-causing widget was:\n MaterialApp\n MaterialApp:file:///Users/name/development/projects/flutter/hello_world/lib/src/hello_world.dart:12:12\n\nWhen the exception was thrown, this was the stack:\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_\ndart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed\npackages/flutter/src/foundation/stack_frame.dart 192:15 fromStackTraceLine\ndart-sdk/lib/internal/iterable.dart 391:20 moveNext\ndart-sdk/lib/internal/iterable.dart …Run Code Online (Sandbox Code Playgroud) 我面临一个关于 的问题Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true。
这是我的调试控制台:
\nE/flutter ( 5236): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2845 pos 18: '!navigator._debugLocked': is not true.\npackage:flutter/\xe2\x80\xa6/widgets/navigator.dart:2845\nE/flutter ( 5236): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)\nE/flutter ( 5236): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)\nE/flutter ( 5236): #2 _RouteEntry.handlePush.<anonymous closure>\npackage:flutter/\xe2\x80\xa6/widgets/navigator.dart:2845\nE/flutter ( 5236): #3 TickerFuture.whenCompleteOrCancel.thunk\npackage:flutter/\xe2\x80\xa6/scheduler/ticker.dart:407\nE/flutter ( 5236): #4 _rootRunUnary (dart:async/zone.dart:1434:47)\nE/flutter ( 5236): #5 _CustomZone.runUnary (dart:async/zone.dart:1335:19)\nE/flutter ( 5236): <asynchronous suspension>\nE/flutter ( 5236): #6 TickerFuture.whenCompleteOrCancel.thunk\npackage:flutter/\xe2\x80\xa6/scheduler/ticker.dart:406\nE/flutter ( 5236): <asynchronous suspension>\nE/flutter ( 5236):\nRun Code Online (Sandbox Code Playgroud)\n … 我在尝试在 DartPad 上运行代码时遇到此问题。
'runZoned' is deprecated and shouldn't be used. This will be removed in v9.0.0. Use Bloc.Bloc.transformer instead...
Run Code Online (Sandbox Code Playgroud)
正确的更换方法是什么?
代码:
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
BlocOverrides.runZoned(
() => runApp(const App()),
blocObserver: AppBlocObserver(),
);
}
/// Custom [BlocObserver] that observes all bloc and cubit state changes.
class AppBlocObserver extends BlocObserver {
@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
if (bloc is Cubit) print(change);
}
@override
void onTransition(Bloc bloc, Transition transition) {
super.onTransition(bloc, transition);
print(transition);
}
}
Run Code Online (Sandbox Code Playgroud) 我是颤振新手。我面临一个关于 的问题[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException。
这是我的调试控制台:
\nLaunching lib\\main.dart on sdk gphone x86 in debug mode...\nlib\\main.dart:1\n\xe2\x88\x9a Built build\\app\\outputs\\flutter-apk\\app-debug.apk.\nW/FlutterActivityAndFragmentDelegate(10702): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.\nConnecting to VM Service at ws://127.0.0.1:59535/02E90npmd4s=/ws\nE/flutter (10702): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(network_error, com.google.android.gms.common.api.ApiException: 7: , null, null)\nE/flutter (10702): #0 StandardMethodCodec.decodeEnvelope\npackage:flutter/\xe2\x80\xa6/services/message_codecs.dart:607\nE/flutter (10702): #1 MethodChannel._invokeMethod\npackage:flutter/\xe2\x80\xa6/services/platform_channel.dart:156\nE/flutter (10702): <asynchronous suspension>\nE/flutter (10702): #2 MethodChannel.invokeMapMethod\npackage:flutter/\xe2\x80\xa6/services/platform_channel.dart:356\nE/flutter (10702): <asynchronous suspension>\nE/flutter (10702): #3 GoogleSignIn._callMethod\npackage:google_sign_in/google_sign_in.dart:244\nE/flutter (10702): <asynchronous suspension>\nE/flutter (10702): #4 GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart)\nE/flutter (10702): <asynchronous suspension>\nE/flutter …Run Code Online (Sandbox Code Playgroud) 我正在尝试新的SegmentedButton小部件:
SegmentedButton<int>(
onSelectionChanged: (i) {},
showSelectedIcon: false,
style: ButtonStyle(
backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
iconColor: MaterialStateProperty.all(Colors.white),
),
segments: const <ButtonSegment<int>>[
ButtonSegment<int>(
value: 12,
icon: Icon(FlutterRemix.thumb_up_fill),
enabled: true,
),
ButtonSegment<int>(
value: 20,
icon: Icon(FlutterRemix.thumb_down_fill),
),
],
selected: {12},
),
Run Code Online (Sandbox Code Playgroud)
此代码显示了两个分段按钮,如下所示:
当我设置时,如何自定义选定和未选定按钮的颜色:
backgroundColor: MaterialStatePropertyAll(Theme.of(context).primaryColor),
Run Code Online (Sandbox Code Playgroud)
它确实为选定的和选定的设置背景颜色。
谢谢你!
我能够在 PaginatoredDataTable 上显示普通文本字段。但我想将 PaginatoredDataTable 上的 Firestore 字段显示为流构建器方法。我在互联网上搜索过,但找不到与我的要求相关的内容。如何将 firestore 数据获取到 PaginatedDataTable 源中。或者有什么其他方法请告诉我。寻找解决方案,如果也有可磁带行或可选择行,则非常有用。我只想从 firestore 获取数据,而不是从 firebase auth 获取数据。我将 firestore 集合名称命名为“users”。我也有所不同 需要帮助 如何做到这一点?如果在PaginatedDataTable 中不可能,DataTable 也可以。
以下是我的示例 Firestore 集合和文档结构:
firestore collection name: users
documentID1-
email: 'email1'
name : 'name1'
role : 'role1'
uid : 'uid1'
documentID2-
email: 'email2'
name : 'name2'
role : 'role2'
uid : 'uid2'
Run Code Online (Sandbox Code Playgroud)
(20多个文件)
下面是我的示例代码,通常能够以普通文本显示:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class AdminDashboard extends StatefulWidget {
const AdminDashboard({Key? key}) : super(key: key);
@override
_AdminDashboardState createState() => _AdminDashboardState();
}
class _AdminDashboardState extends State<AdminDashboard> …Run Code Online (Sandbox Code Playgroud) 我需要在每个之间添加一个分隔线NavigationRailDestination。里面 NavigationRail有我们添加的目的地NavigationRailDestination。
它只接受 type 的孩子NavigationRailDestination。
我尝试以这种方式执行此操作,但这不是我想要的,有不必要的填充,我无法使用它,并且当我单击它时它会执行操作
这是我的代码:
NavigationRail(
backgroundColor: customTheme.card,
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: Icon(
FeatherIcons.chevronLeft,
size: 20,
color: theme.colorScheme.onBackground,
)),
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) {
setState(() {
_selectedIndex = index;
controller.animateToPage(index,
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut);
});
},
labelType: NavigationRailLabelType.selected,
/*------------- Build Tabs -------------------*/
destinations: [
NavigationRailDestination(
icon: const Icon(Icons.dashboard),
selectedIcon: const Icon(Icons.dashboard),
label: FxText.titleSmall('Dashboard',
fontWeight: 500, color: theme.colorScheme.primary),
),
NavigationRailDestination(
icon: Divider(color: Colors.black),
selectedIcon: Divider(color: Colors.black), …Run Code Online (Sandbox Code Playgroud) flutter ×9
dart ×8
flutter-web ×2
bloc ×1
firebase ×1
flutter-bloc ×1
malformed ×1
python ×1
valueerror ×1