301 lines
9.7 KiB
Dart
301 lines
9.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_passvault/constant/constantfile.dart';
|
|
import 'package:flutter_passvault/custom_widgets/reuse_button.dart';
|
|
import 'package:flutter_passvault/modelclasses/jsomdata.dart';
|
|
import 'package:flutter_passvault/custom_widgets/reuse_textview.dart';
|
|
import 'package:flutter_passvault/view_pages/edit_credential.dart';
|
|
import 'package:flutter_passvault/view_pages/sharecredential.dart';
|
|
import 'package:flutter_passvault/view_pages/shared_preferance.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class ViewDetilsScreen extends StatefulWidget {
|
|
const ViewDetilsScreen(
|
|
{super.key, required this.jsondata, required this.index});
|
|
|
|
final JsonData jsondata;
|
|
final int index;
|
|
|
|
@override
|
|
State<ViewDetilsScreen> createState() => _ViewDetilsScreenState();
|
|
}
|
|
|
|
class _ViewDetilsScreenState extends State<ViewDetilsScreen> {
|
|
Color color1 = ApiConstants.backgroundcolor;
|
|
|
|
String fontfamily = ApiConstants.fontFamily;
|
|
|
|
String? userid;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getnameid();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
DateTime dateTime = DateTime.parse(widget.jsondata.updatedAt.toString());
|
|
DateTime localTime = dateTime.toLocal();
|
|
|
|
String formattedDate = DateFormat('dd-MM-yyyy HH:mm').format(localTime);
|
|
|
|
final List<ListItem> items11 = [
|
|
ListItem(title: 'Application Name', isPasswordField: false),
|
|
ListItem(title: 'Username', isPasswordField: false),
|
|
ListItem(title: 'Password', isPasswordField: true),
|
|
ListItem(title: 'Description', isPasswordField: false),
|
|
ListItem(title: 'Updated at', isPasswordField: false),
|
|
];
|
|
final List<String> items1 = [
|
|
widget.jsondata.name,
|
|
widget.jsondata.username,
|
|
widget.jsondata.password,
|
|
widget.jsondata.detail,
|
|
formattedDate,
|
|
];
|
|
|
|
print(" widget : ${widget.jsondata.updatedAt}");
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: color1,
|
|
title: const Text(
|
|
'Credential Info',
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
|
actions: [
|
|
userid == widget.jsondata.createdBy.toString()
|
|
? IconButton(
|
|
icon: const Padding(
|
|
padding: EdgeInsets.only(right: 28.0),
|
|
child: Icon(Icons.share, color: Colors.white),
|
|
),
|
|
onPressed: () {
|
|
print("widget.jsondata.id: ${widget.jsondata.id}");
|
|
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ShareDataToUsr(
|
|
credentialjsondata: widget.jsondata,
|
|
// userid: widget.jsondata.pivot!.userId,
|
|
userid: int.parse(userid!),
|
|
),
|
|
));
|
|
},
|
|
)
|
|
: Container()
|
|
]),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView.builder(
|
|
shrinkWrap: true,
|
|
itemCount: items11.length,
|
|
itemBuilder: (context, index) {
|
|
final items = items11[index];
|
|
|
|
final itemspwd = items1[index];
|
|
|
|
bool shouldShowTrailingIcon =
|
|
itemspwd == formattedDate; // Replace with your condition
|
|
|
|
if (items.isPasswordField) {
|
|
return CustomListTileWithPasswordAndCopyIcon(
|
|
itemspwd.toString());
|
|
}
|
|
|
|
if (itemspwd.isEmpty) {
|
|
print("IAm_empty");
|
|
return Container();
|
|
} else {
|
|
return Card(
|
|
surfaceTintColor: Colors.white,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(0.0),
|
|
),
|
|
),
|
|
elevation: 4,
|
|
child: ListTile(
|
|
title: ReusableTextView(
|
|
text: items.title,
|
|
// ignore: prefer_const_constructors
|
|
textStyle: TextStyle(
|
|
fontFamily: fontfamily,
|
|
color: Colors.black,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
subtitle: ReusableTextView(
|
|
text: items1[index],
|
|
// ignore: prefer_const_constructors
|
|
textStyle: TextStyle(
|
|
fontFamily: fontfamily,
|
|
color: Colors.black,
|
|
fontSize: 17,
|
|
),
|
|
),
|
|
trailing: shouldShowTrailingIcon
|
|
? null
|
|
: InkWell(
|
|
onTap: () async {
|
|
//copyToClipboard(items[index]);
|
|
fluttertoast();
|
|
|
|
await Clipboard.setData(
|
|
ClipboardData(text: items1[index]));
|
|
},
|
|
child: const Icon(Icons.copy)),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
|
|
// ),
|
|
// ],
|
|
),
|
|
),
|
|
userid == widget.jsondata.createdBy.toString()
|
|
? Padding(
|
|
padding: const EdgeInsets.only(top: 0.0, bottom: 16.0),
|
|
child: ReusableButton(
|
|
isRounded: true,
|
|
color: const Color.fromARGB(255, 39, 121, 42),
|
|
text: 'EDIT',
|
|
onPressed: () async {
|
|
print("hiii");
|
|
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ViewCdrentialontap(
|
|
jsondata: widget.jsondata, index: widget.index),
|
|
));
|
|
},
|
|
),
|
|
)
|
|
: Container(),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void getnameid() async {
|
|
String? userid1 = await CustomSharedPreferences.getuserid() ?? "";
|
|
|
|
setState(() {
|
|
userid = userid1;
|
|
});
|
|
}
|
|
|
|
void fluttertoast() {
|
|
Fluttertoast.showToast(
|
|
msg: "Copied",
|
|
toastLength: Toast.LENGTH_SHORT,
|
|
gravity: ToastGravity.BOTTOM,
|
|
timeInSecForIosWeb: 1,
|
|
backgroundColor: Colors.grey,
|
|
textColor: Colors.white,
|
|
fontSize: 16.0);
|
|
}
|
|
}
|
|
|
|
class ListItem {
|
|
final String title;
|
|
final bool isPasswordField;
|
|
|
|
ListItem({required this.title, this.isPasswordField = false});
|
|
}
|
|
|
|
class CustomListTileWithPasswordAndCopyIcon extends StatefulWidget {
|
|
final String item;
|
|
|
|
const CustomListTileWithPasswordAndCopyIcon(this.item, {super.key});
|
|
|
|
@override
|
|
State<CustomListTileWithPasswordAndCopyIcon> createState() =>
|
|
_CustomListTileWithPasswordAndCopyIconState();
|
|
}
|
|
|
|
class _CustomListTileWithPasswordAndCopyIconState
|
|
extends State<CustomListTileWithPasswordAndCopyIcon> {
|
|
bool isPasswordVisible = false;
|
|
|
|
var fontfamily = ApiConstants.fontFamily;
|
|
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
Color color1 = ApiConstants.backgroundcolor;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_controller.text = widget.item.toString();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
surfaceTintColor: Colors.white,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(0.0),
|
|
),
|
|
),
|
|
elevation: 4,
|
|
child: ListTile(
|
|
title: ReusableTextView(
|
|
text: "Password",
|
|
// ignore: prefer_const_constructors
|
|
textStyle: TextStyle(
|
|
fontFamily: fontfamily,
|
|
color: Colors.black,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
subtitle: TextField(
|
|
readOnly: true,
|
|
controller: _controller,
|
|
obscureText: !isPasswordVisible, // Secure text when not visible
|
|
|
|
decoration: const InputDecoration(border: InputBorder.none),
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
// Toggle password visibility
|
|
setState(() {
|
|
isPasswordVisible = !isPasswordVisible;
|
|
});
|
|
},
|
|
child: Icon(
|
|
isPasswordVisible ? Icons.visibility : Icons.visibility_off,
|
|
color: isPasswordVisible ? color1 : Colors.grey),
|
|
),
|
|
const SizedBox(width: 16.0), // Add spacing between the icons
|
|
GestureDetector(
|
|
onTap: () async {
|
|
await Clipboard.setData(
|
|
ClipboardData(text: widget.item.toString()));
|
|
Fluttertoast.showToast(
|
|
msg: "Copied",
|
|
toastLength: Toast.LENGTH_SHORT,
|
|
gravity: ToastGravity.BOTTOM,
|
|
timeInSecForIosWeb: 1,
|
|
backgroundColor: Colors.grey,
|
|
textColor: Colors.white,
|
|
fontSize: 16.0);
|
|
},
|
|
child: const Icon(Icons.copy),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|