小编S. *_*GIR的帖子

Flutter GetX Get.back() 或 navigator.pop() 从内存中删除控制器并且无法重新创建它

我有两个页面:HomePageDetailsPage以及关联的GetxControllers

主页

class HomePage extends GetView<HomeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('HomePage')),
      body: Container(
        child: Obx(
          () => ListView.builder(
            itemCount: controller.task.length,
            itemBuilder: (context, index) {
              return ListTile(
                leading: Text('${index + 1}'),
                title: Text(controller.task[index]["name"]),
                onTap: () {
                  Get.to(
                    DetailsPage(),
                    arguments: controller.task[index]["name"],
                  );
                },
              );
            },
          ),
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

家庭控制器

class HomeController extends GetxController {
  final TaskRepository repository;
  HomeController({@required this.repository}) : assert(repository != null);

  final _task …
Run Code Online (Sandbox Code Playgroud)

dependency-injection dart flutter flutter-getx

16
推荐指数
2
解决办法
6万
查看次数

使用 MultipartFile GetConnect 发送 FormData 时需要字段“field”

我正在尝试发出put请求以使用GetConnect更新用户配置文件。用户个人资料采用一些普通的 JSON 字段和一个用于个人资料图片的MultipartFile 。

这是我的ProfileProvider类:

class ProfileProvider extends GetConnect {
 Future<ProfileModel> updateProfile({
  String name,
  String email,
  String address,
  File avatar,
 }) async {

 final headers = {
  "Authorization": "Bearer $token",
  "Content-Type": "application/json",
  "Accept": "application/json",
};

String fileName = avatar.path.split("/").last;
final form = FormData({
  "name": name,
  "email": email,
  "address": address,
  "avatar": MultipartFile(avatar, filename: fileName),
});

final response = await put(url, form, headers: headers);

if (response.statusCode == 200) {
  final profileModel = ProfileModel.fromJson(response.bodyString);

  return profileModel;
   } …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-getx

5
推荐指数
1
解决办法
2807
查看次数