Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 730
Nick Avatar asked Dec 31 '22 23:12

Nick


1 Answers

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;

.....
like image 190
Haroun Hajem Avatar answered Mar 15 '23 09:03

Haroun Hajem