asset tagging
parent
5658059543
commit
e4f2089126
@ -1,75 +1,151 @@
|
||||
import 'package:flutter/material.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/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/no_data_found.dart';
|
||||
|
||||
class AssetTagListView extends StatelessWidget {
|
||||
AssetTagListView({Key? key}) : super(key: key);
|
||||
class AssetTagListView extends StatefulWidget {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: const DefaultAppBar(title: "Available Tags"),
|
||||
body: SizedBox());
|
||||
appBar: const DefaultAppBar(title: "Available Tracking Tags"),
|
||||
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>(
|
||||
// future: Provider.of<AssetTrackingProvider>(context, listen: false).getPenguinAssetTags(),
|
||||
// builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
|
||||
// if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
// return const Center(child: ALoading());
|
||||
// } else if (snapshot.hasData) {}
|
||||
//
|
||||
// return SizedBox();
|
||||
//
|
||||
// // return ListView.separated(
|
||||
// // key: const ValueKey('list_view'),
|
||||
// // padding: const EdgeInsets.all(16),
|
||||
// // itemCount: _searchableList.length,
|
||||
// // separatorBuilder: (listContext, itemIndex) => 12.height,
|
||||
// // itemBuilder: (listContext, itemIndex) {
|
||||
// // // Calculate staggered animation delay
|
||||
// // 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,
|
||||
// // ),
|
||||
// // ),
|
||||
// // );
|
||||
// //
|
||||
// // 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);
|
||||
// // },
|
||||
// // ),
|
||||
// // ),
|
||||
// // );
|
||||
// // },
|
||||
// // );
|
||||
// }));
|
||||
return FadeTransition(
|
||||
opacity: animation,
|
||||
child: SlideTransition(
|
||||
position: slideAnimation,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
InfoHeaderWidget(provider.tagList[itemIndex].label!),
|
||||
InfoTextWidget(label: "TagID", value: provider.tagList[itemIndex].tagID, showEmptyValue: true),
|
||||
InfoTextWidget(label: "Mac Address", value: provider.tagList[itemIndex].macAddress, showEmptyValue: true),
|
||||
],
|
||||
).toShadowContainer(context))
|
||||
.onPress(() async {
|
||||
bool result = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => AAlertDialog(
|
||||
title: "Confirm".addTranslation,
|
||||
content: 'You are assigning\n'
|
||||
'"${provider.tagList[itemIndex].label!}" -> "${widget.assetName}(${widget.assetNumber})"'
|
||||
.addTranslation,
|
||||
button1Text: "Assign",
|
||||
),
|
||||
);
|
||||
if (result) {
|
||||
Utils.showLoading(context);
|
||||
result = await Provider.of<AssetProvider>(context, listen: false).linkAssetWithPenguinTag(widget.assetId, provider.tagList[itemIndex].id!);
|
||||
Utils.hideLoading(context);
|
||||
if (result) {
|
||||
Navigator.pop(context, result);
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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