asset tagging
parent
5658059543
commit
e4f2089126
@ -1,75 +1,151 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
||||||
|
import 'package:test_sa/extensions/context_extension.dart';
|
||||||
|
import 'package:test_sa/extensions/int_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/string_extensions.dart';
|
||||||
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||||
|
import 'package:test_sa/helper/utils.dart';
|
||||||
|
import 'package:test_sa/models/lookup.dart';
|
||||||
import 'package:test_sa/modules/asset_tracking/asset_tracking_provider.dart';
|
import 'package:test_sa/modules/asset_tracking/asset_tracking_provider.dart';
|
||||||
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
||||||
|
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||||
|
import 'package:test_sa/views/widgets/dialogs/dialog.dart';
|
||||||
|
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
|
||||||
|
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
|
||||||
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
|
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
|
||||||
|
import 'package:test_sa/views/widgets/loaders/no_data_found.dart';
|
||||||
|
|
||||||
class AssetTagListView extends StatelessWidget {
|
class AssetTagListView extends StatefulWidget {
|
||||||
AssetTagListView({Key? key}) : super(key: key);
|
int assetId;
|
||||||
|
String assetName;
|
||||||
|
String assetNumber;
|
||||||
|
|
||||||
|
AssetTagListView(this.assetId, this.assetName, this.assetNumber, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_AssetTagListViewState createState() {
|
||||||
|
return _AssetTagListViewState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AssetTagListViewState extends State<AssetTagListView> with SingleTickerProviderStateMixin {
|
||||||
|
late AnimationController _animationController;
|
||||||
|
late AssetTrackingProvider assetTrackingProvider;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
assetTrackingProvider = Provider.of<AssetTrackingProvider>(context, listen: false);
|
||||||
|
assetTrackingProvider.resetAssetTagData();
|
||||||
|
_animationController = AnimationController(
|
||||||
|
duration: const Duration(milliseconds: 1200),
|
||||||
|
vsync: this,
|
||||||
|
);
|
||||||
|
_animationController.forward();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
assetTrackingProvider.getPenguinAssetTags();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const DefaultAppBar(title: "Available Tags"),
|
appBar: const DefaultAppBar(title: "Available Tracking Tags"),
|
||||||
body: SizedBox());
|
body: Consumer<AssetTrackingProvider>(builder: (context, provider, _) {
|
||||||
|
return provider.isLoadingAssetTags && provider.tagList.isEmpty
|
||||||
|
? const Center(child: ALoading())
|
||||||
|
: (provider.tagList.isEmpty && !provider.isLoading)
|
||||||
|
? NoDataFound(message: context.translation.noDataFound).center
|
||||||
|
: NotificationListener<ScrollNotification>(
|
||||||
|
onNotification: (scrollInfo) {
|
||||||
|
if (provider.isCanLoadMore && scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
|
||||||
|
assetTrackingProvider.getPenguinAssetTags();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
child: SafeArea(
|
||||||
|
child: ListView.separated(
|
||||||
|
key: const ValueKey('asset-tag-list-view'),
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
itemCount: provider.tagList.length + (provider.isLoadingAssetTags ? 1 : 0),
|
||||||
|
separatorBuilder: (listContext, itemIndex) => 12.height,
|
||||||
|
itemBuilder: (listContext, itemIndex) {
|
||||||
|
if (itemIndex == provider.tagList.length) {
|
||||||
|
return const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 16),
|
||||||
|
child: ALoading(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final delay = itemIndex * 0.08;
|
||||||
|
final animation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||||
|
CurvedAnimation(
|
||||||
|
parent: _animationController,
|
||||||
|
curve: Interval(
|
||||||
|
delay.clamp(0.0, 0.7),
|
||||||
|
(delay + 0.4).clamp(0.0, 1.0),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final slideAnimation = Tween<Offset>(
|
||||||
|
begin: const Offset(0.0, 0.15),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(
|
||||||
|
CurvedAnimation(
|
||||||
|
parent: _animationController,
|
||||||
|
curve: Interval(
|
||||||
|
delay.clamp(0.0, 0.7),
|
||||||
|
(delay + 0.4).clamp(0.0, 1.0),
|
||||||
|
curve: Curves.easeOutCubic,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// FutureBuilder<List>(
|
return FadeTransition(
|
||||||
// future: Provider.of<AssetTrackingProvider>(context, listen: false).getPenguinAssetTags(),
|
opacity: animation,
|
||||||
// builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
|
child: SlideTransition(
|
||||||
// if (snapshot.connectionState == ConnectionState.waiting) {
|
position: slideAnimation,
|
||||||
// return const Center(child: ALoading());
|
child: Column(
|
||||||
// } else if (snapshot.hasData) {}
|
mainAxisSize: MainAxisSize.min,
|
||||||
//
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
// return SizedBox();
|
children: [
|
||||||
//
|
InfoHeaderWidget(provider.tagList[itemIndex].label!),
|
||||||
// // return ListView.separated(
|
InfoTextWidget(label: "TagID", value: provider.tagList[itemIndex].tagID, showEmptyValue: true),
|
||||||
// // key: const ValueKey('list_view'),
|
InfoTextWidget(label: "Mac Address", value: provider.tagList[itemIndex].macAddress, showEmptyValue: true),
|
||||||
// // padding: const EdgeInsets.all(16),
|
],
|
||||||
// // itemCount: _searchableList.length,
|
).toShadowContainer(context))
|
||||||
// // separatorBuilder: (listContext, itemIndex) => 12.height,
|
.onPress(() async {
|
||||||
// // itemBuilder: (listContext, itemIndex) {
|
bool result = await showDialog(
|
||||||
// // // Calculate staggered animation delay
|
context: context,
|
||||||
// // final delay = itemIndex * 0.08;
|
builder: (_) => AAlertDialog(
|
||||||
// // final animation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
title: "Confirm".addTranslation,
|
||||||
// // CurvedAnimation(
|
content: 'You are assigning\n'
|
||||||
// // parent: _animationController,
|
'"${provider.tagList[itemIndex].label!}" -> "${widget.assetName}(${widget.assetNumber})"'
|
||||||
// // curve: Interval(
|
.addTranslation,
|
||||||
// // delay.clamp(0.0, 0.7),
|
button1Text: "Assign",
|
||||||
// // (delay + 0.4).clamp(0.0, 1.0),
|
),
|
||||||
// // curve: Curves.easeOut,
|
);
|
||||||
// // ),
|
if (result) {
|
||||||
// // ),
|
Utils.showLoading(context);
|
||||||
// // );
|
result = await Provider.of<AssetProvider>(context, listen: false).linkAssetWithPenguinTag(widget.assetId, provider.tagList[itemIndex].id!);
|
||||||
// //
|
Utils.hideLoading(context);
|
||||||
// // final slideAnimation = Tween<Offset>(
|
if (result) {
|
||||||
// // begin: const Offset(0.0, 0.15),
|
Navigator.pop(context, result);
|
||||||
// // end: Offset.zero,
|
}
|
||||||
// // ).animate(
|
}
|
||||||
// // CurvedAnimation(
|
}),
|
||||||
// // parent: _animationController,
|
);
|
||||||
// // curve: Interval(
|
},
|
||||||
// // delay.clamp(0.0, 0.7),
|
),
|
||||||
// // (delay + 0.4).clamp(0.0, 1.0),
|
),
|
||||||
// // curve: Curves.easeOutCubic,
|
);
|
||||||
// // ),
|
}));
|
||||||
// // ),
|
|
||||||
// // );
|
|
||||||
// //
|
|
||||||
// // return FadeTransition(
|
|
||||||
// // opacity: animation,
|
|
||||||
// // child: SlideTransition(
|
|
||||||
// // position: slideAnimation,
|
|
||||||
// // child: AssetItemListView(
|
|
||||||
// // device: _searchableList[itemIndex],
|
|
||||||
// // onPressed: (device) {
|
|
||||||
// // widget.fromBottomBar ? Navigator.of(context).pushNamed(AssetDetailPage.id, arguments: device.id) : Navigator.of(context).pop(device);
|
|
||||||
// // },
|
|
||||||
// // ),
|
|
||||||
// // ),
|
|
||||||
// // );
|
|
||||||
// // },
|
|
||||||
// // );
|
|
||||||
// }));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
class AssetTagModel {
|
||||||
|
int? id;
|
||||||
|
String? tagID;
|
||||||
|
String? label;
|
||||||
|
String? macAddress;
|
||||||
|
String? type;
|
||||||
|
String? status;
|
||||||
|
String? assetName;
|
||||||
|
String? assetNumber;
|
||||||
|
|
||||||
|
AssetTagModel(
|
||||||
|
{this.id,
|
||||||
|
this.tagID,
|
||||||
|
this.label,
|
||||||
|
this.macAddress,
|
||||||
|
this.type,
|
||||||
|
this.status,
|
||||||
|
this.assetName,
|
||||||
|
this.assetNumber});
|
||||||
|
|
||||||
|
AssetTagModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
tagID = json['tagID'];
|
||||||
|
label = json['label'];
|
||||||
|
macAddress = json['macAddress'];
|
||||||
|
type = json['type'];
|
||||||
|
status = json['status'];
|
||||||
|
assetName = json['assetName'];
|
||||||
|
assetNumber = json['assetNumber'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['id'] = this.id;
|
||||||
|
data['tagID'] = this.tagID;
|
||||||
|
data['label'] = this.label;
|
||||||
|
data['macAddress'] = this.macAddress;
|
||||||
|
data['type'] = this.type;
|
||||||
|
data['status'] = this.status;
|
||||||
|
data['assetName'] = this.assetName;
|
||||||
|
data['assetNumber'] = this.assetNumber;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue