我有一个 flutter 应用程序,它通过 REST api 与服务器交互,可以获取和显示信息。它还可以向服务器发送文本信息。我想添加将 pdf 文件和图像发送到服务器的功能,但我不知道如何实现。这是选择文件的代码
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Another Attempt'),
centerTitle: true,
),
body: Container(
alignment: Alignment.topCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MaterialButton(
onPressed: () async {
FilePickerResult result =
await FilePicker.platform.pickFiles(allowMultiple: true);
if (result != null) {
List<File> files =
result.paths.map((path) => File(path)).toList();
} else {
// User canceled the picker
}
},
child: Text('Upload multiple files'),
color: Colors.blueAccent,
),
SizedBox(height: 10.0),
MaterialButton(
onPressed: () async {
FilePickerResult …Run Code Online (Sandbox Code Playgroud) 我正在尝试将包permission_handler添加到我的flutter项目中,但我无法运行该应用程序。我收到构建错误。这是我得到的错误
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:321: error: cannot find symbol
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
^
symbol: variable S
location: class VERSION_CODES
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:72: error: cannot find symbol
case Manifest.permission.BLUETOOTH_SCAN:
^
symbol: variable BLUETOOTH_SCAN
location: class permission
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:74: error: cannot find symbol
case Manifest.permission.BLUETOOTH_ADVERTISE:
^
symbol: variable BLUETOOTH_ADVERTISE
location: class permission
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:76: error: cannot find symbol
case Manifest.permission.BLUETOOTH_CONNECT:
^
symbol: variable BLUETOOTH_CONNECT
location: class permission
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:259: error: cannot
find symbol
String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_SCAN);
^
symbol: variable BLUETOOTH_SCAN
location: class permission
C:\Users\Hp\dev\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:270: error: cannot …Run Code Online (Sandbox Code Playgroud) 我正在尝试加载并显示 svg 格式的图像,但每次都会收到此错误
\nunhandled element pattern; Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#5abbc(), name: "assets/svg/Ellipse.svg", colorFilter: null)\n\xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY SVG \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\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 while parsing AssetBundlePictureKey(bundle:\nPlatformAssetBundle#5abbc(), name: "assets/svg/Ellipse.svg", colorFilter: null) in\n_getDefinitionPaint:\nFailed to find definition for url(#pattern0)\nThis library only supports <defs> and xlink:href references that are defined ahead of their\nreferences.\nThis error can be caused when the desired definition is defined after the element referring to it\n(e.g. at the end of the file), or defined in another file.\nThis error is treated …Run Code Online (Sandbox Code Playgroud) 我最近构建了一个颤振应用程序。我有一种方法可以检查用户是否登录并在确认检查后显示适当的屏幕。如果用户未登录,它将返回登录屏幕,但如果用户已经登录,则应显示主屏幕。但是,如果用户已登录,它将在显示主屏幕之前显示登录屏幕一两秒钟。检查用户是否登录的代码
class CheckAuth extends StatefulWidget {
@override
_CheckAuthState createState() => _CheckAuthState();
}
class _CheckAuthState extends State<CheckAuth> {
bool isAuth = false;
@override
void initState() {
super.initState();
_checkIfLoggedIn();
}
void _checkIfLoggedIn() async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
var token = localStorage.getString('token');
if (token != null) {
setState(() {
isAuth = true;
});
}
}
@override
Widget build(BuildContext context) {
Widget child;
if (isAuth) {
child = HomePage();
} else {
child = Login();
}
return Scaffold(
body: child,
);
} …Run Code Online (Sandbox Code Playgroud) 我有一个 flutter 应用程序,可以使用屏幕中的文本表单字段捕获数据。我有第二个屏幕,我想在其中显示从第一个屏幕的文本表单字段捕获的数据。
但首先我想从第二个屏幕控制器将其打印到终端,并查看已传递的内容。我尝试使用 GetX naviagtion 并传递,但出现此错误
The method '[]' was called on null.
Receiver: null
Tried calling: [](0)
Run Code Online (Sandbox Code Playgroud)
这是我用来获取数据作为输入的文本表单字段
TextFormField(
controller: controller._phoneNumberController,
keyboardType: TextInputType.text,
validator: (value) => validatePhoneNumber(value!),
style: TextStyle(
color: accentColor,
fontSize: 15,
fontFamily: 'PoppinsRegular',
),
decoration: InputDecoration(
hintText: "Phone Number",
hintStyle: TextStyle(
fontSize: 14,
color: Colors.black45,
fontWeight: FontWeight.w500),
fillColor: Color(0xffEBEDF4),
filled: true,
border: InputBorder.none,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: Color(0xff1D275C),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide(
color: formFieldColor,
width: 2.0,
),
),
), …Run Code Online (Sandbox Code Playgroud)