check image for null safety
This commit is contained in:
@@ -8,17 +8,26 @@ class DisplayImageSource {
|
|||||||
File? file;
|
File? file;
|
||||||
DisplayImageSource({this.url, this.file});
|
DisplayImageSource({this.url, this.file});
|
||||||
|
|
||||||
ImageProvider? get imageProvider =>
|
ImageProvider get imageProvider {
|
||||||
file == null ? CachedNetworkImageProvider(url!) : FileImage(file!);
|
if (file == null) {
|
||||||
|
return CachedNetworkImageProvider(url!);
|
||||||
|
} else {
|
||||||
|
return FileImage(file!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
if (identical(this, other)) {
|
if (identical(this, other) && other is DisplayImageSource) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return (other.file == this.file &&
|
|
||||||
|
return (other is DisplayImageSource &&
|
||||||
|
other.file == this.file &&
|
||||||
(other.file != null || this.file != null)) ||
|
(other.file != null || this.file != null)) ||
|
||||||
(other.url == this.url && (other.url != null || this.url != null));
|
(other is DisplayImageSource &&
|
||||||
|
other.url == this.url &&
|
||||||
|
(other.url != null || this.url != null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'local_text.dart';
|
|||||||
|
|
||||||
typedef OnFile = void Function(File);
|
typedef OnFile = void Function(File);
|
||||||
|
|
||||||
modelBottomSheet(BuildContext context, {final OnFile onFile}) {
|
modelBottomSheet(BuildContext context, {final OnFile? onFile}) {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
elevation: 10,
|
elevation: 10,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
@@ -84,7 +84,7 @@ class _ImageFileState extends State<ImageFile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pickImage(ImageSource source) async {
|
pickImage(ImageSource source) async {
|
||||||
var tempImage = await ImagePicker.pickImage(source: source);
|
var tempImage = await ImagePicker().pickImage(source: source);
|
||||||
return tempImage;
|
return tempImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
@@ -7,19 +8,19 @@ import 'package:image_picker/image_picker.dart';
|
|||||||
|
|
||||||
import 'show_img.dart';
|
import 'show_img.dart';
|
||||||
|
|
||||||
typedef OnFile = void Function(File);
|
typedef OnFile = void Function(File?);
|
||||||
|
|
||||||
class LocalImagePicker extends StatefulWidget {
|
class LocalImagePicker extends StatefulWidget {
|
||||||
final Color color;
|
final Color? color;
|
||||||
final String title;
|
final String title;
|
||||||
final OnFile onFile;
|
final OnFile? onFile;
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
final String initialImgUrl;
|
final String? initialImgUrl;
|
||||||
final ImageSource imageSource;
|
final ImageSource imageSource;
|
||||||
|
|
||||||
const LocalImagePicker(
|
const LocalImagePicker(
|
||||||
{Key key,
|
{Key? key,
|
||||||
this.title,
|
required this.title,
|
||||||
this.onFile,
|
this.onFile,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
this.initialImgUrl,
|
this.initialImgUrl,
|
||||||
@@ -31,8 +32,8 @@ class LocalImagePicker extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LocalImagePickerState extends State<LocalImagePicker> {
|
class _LocalImagePickerState extends State<LocalImagePicker> {
|
||||||
String url;
|
String? url;
|
||||||
File file;
|
File? file;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -56,16 +57,16 @@ class _LocalImagePickerState extends State<LocalImagePicker> {
|
|||||||
await _dialog(
|
await _dialog(
|
||||||
context, () => camera = true, () => gallery = true);
|
context, () => camera = true, () => gallery = true);
|
||||||
if (camera || gallery) {
|
if (camera || gallery) {
|
||||||
var selectedFile = await ImagePicker.pickImage(
|
var selectedFile = await ImagePicker().pickImage(
|
||||||
source: camera ? ImageSource.camera : ImageSource.gallery,
|
source: camera ? ImageSource.camera : ImageSource.gallery,
|
||||||
imageQuality: 80,
|
imageQuality: 80,
|
||||||
maxWidth: 1000);
|
maxWidth: 1000);
|
||||||
if (selectedFile != null) {
|
if (selectedFile != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.file = selectedFile;
|
this.file = File(selectedFile.path);
|
||||||
});
|
});
|
||||||
if (widget.onFile != null) {
|
if (widget.onFile != null) {
|
||||||
widget.onFile(selectedFile);
|
widget.onFile!(File(selectedFile.path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,7 @@ class _LocalImagePickerState extends State<LocalImagePicker> {
|
|||||||
this.file = null;
|
this.file = null;
|
||||||
this.url = null;
|
this.url = null;
|
||||||
if (widget.onFile != null) {
|
if (widget.onFile != null) {
|
||||||
widget.onFile(null);
|
widget.onFile!(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ class _LengthPickerDialogState extends State<LengthPickerDialog> {
|
|||||||
borderSide: BorderSide(color: primaryColor, width: 1.0),
|
borderSide: BorderSide(color: primaryColor, width: 1.0),
|
||||||
),
|
),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0),
|
borderSide:
|
||||||
|
BorderSide(color: Colors.grey.shade400, width: 1.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -196,7 +197,8 @@ class _LengthPickerDialogState extends State<LengthPickerDialog> {
|
|||||||
borderSide: BorderSide(color: primaryColor, width: 1.0),
|
borderSide: BorderSide(color: primaryColor, width: 1.0),
|
||||||
),
|
),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.grey.shade400, width: 1.0),
|
borderSide:
|
||||||
|
BorderSide(color: Colors.grey.shade400, width: 1.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -273,7 +275,7 @@ class _LengthPickerDialogState extends State<LengthPickerDialog> {
|
|||||||
min: 0,
|
min: 0,
|
||||||
max: MAX_FEET,
|
max: MAX_FEET,
|
||||||
divisions: 100,
|
divisions: 100,
|
||||||
label: (_valueFeet ?? 0).round().toString(),
|
label: _valueFeet.round().toString(),
|
||||||
onChanged: (double v) {
|
onChanged: (double v) {
|
||||||
_updateFeet(v);
|
_updateFeet(v);
|
||||||
},
|
},
|
||||||
@@ -301,7 +303,7 @@ class _LengthPickerDialogState extends State<LengthPickerDialog> {
|
|||||||
min: 0,
|
min: 0,
|
||||||
max: widget.displayFeet! ? 11 : MAX_INC,
|
max: widget.displayFeet! ? 11 : MAX_INC,
|
||||||
divisions: 100,
|
divisions: 100,
|
||||||
label: (_valueInc ?? 0).round().toString(),
|
label: _valueInc.round().toString(),
|
||||||
onChanged: (double v) {
|
onChanged: (double v) {
|
||||||
_updateInc(v);
|
_updateInc(v);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import 'display_image_source.dart';
|
|||||||
|
|
||||||
class MultiImgController {
|
class MultiImgController {
|
||||||
List<String> imageUrls = [];
|
List<String> imageUrls = [];
|
||||||
List<File> imageFiles = [];
|
List<File?> imageFiles = [];
|
||||||
List<DisplayImageSource> addedFiles = [];
|
List<DisplayImageSource> addedFiles = [];
|
||||||
List<DisplayImageSource> removedFiles = [];
|
List<DisplayImageSource> removedFiles = [];
|
||||||
|
|
||||||
List<DisplayImageSource> fileContainers = [];
|
List<DisplayImageSource> fileContainers = [];
|
||||||
CallBack callback;
|
CallBack? callback;
|
||||||
MultiImgController() {
|
MultiImgController() {
|
||||||
fileContainers = [];
|
fileContainers = [];
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ class MultiImgController {
|
|||||||
fileContainers.add(DisplayImageSource(url: e));
|
fileContainers.add(DisplayImageSource(url: e));
|
||||||
});
|
});
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback();
|
callback!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class MultiImgController {
|
|||||||
fileContainers.add(DisplayImageSource(file: e));
|
fileContainers.add(DisplayImageSource(file: e));
|
||||||
});
|
});
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback();
|
callback!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class MultiImgController {
|
|||||||
// if (fileContainers.contains(fileContainer)) return;
|
// if (fileContainers.contains(fileContainer)) return;
|
||||||
addedFiles.add(fileContainer);
|
addedFiles.add(fileContainer);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback();
|
callback!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +74,11 @@ class MultiImgController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback();
|
callback!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> get getUpdatedFile {
|
List<File?> get getUpdatedFile {
|
||||||
List<File?> _addfiles = getAddedFile;
|
List<File?> _addfiles = getAddedFile;
|
||||||
this.imageFiles.addAll(_addfiles);
|
this.imageFiles.addAll(_addfiles);
|
||||||
return this.imageFiles;
|
return this.imageFiles;
|
||||||
|
|||||||
Reference in New Issue
Block a user