简体   繁体   中英

How can I access global data from another class in Flutter?

I have a simple class like;

import 'dart:io';
class IDCardClass {
  File frontImageFile;
  File backImageFile;
}

From front_test.dart class I need to assign a data to frontImageFile and back_test.dart class I need to assign a data to backImageFile .

In my home.dart or another ***.dart class I need to get frontImageFile and backImageFile to show it to user.

My question is How can I access global data from another class in Flutter?

Make the variables to static like this:

class IDCardClass {
  static File frontImageFile;
  static File backImageFile;
}

Just import the class into the other class and access the variables.

import 'package:your_projectname/your_folder/IDCardClass.dart';

.....

var imageFile = IDCardClass.frontImageFile;

.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM