Skip to content

Commit

Permalink
fix: write nfc ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ezeanyimhenry committed Aug 1, 2024
1 parent 89ad595 commit dfec869
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 87 deletions.
4 changes: 4 additions & 0 deletions assets/icons/svg/paste.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 101 additions & 81 deletions lib/presentation/screens/write-nfc/text_record_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:nfc_app/constants/app_colors.dart';
import 'package:nfc_app/constants/app_spacing.dart';
import 'package:nfc_app/constants/app_textstyles.dart';
import 'package:nfc_app/notifier/nfc_notifier.dart';
import 'package:nfc_app/presentation/screens/history/models/history_model.dart';
import 'package:nfc_app/presentation/screens/translate/translate_screen.dart';
Expand Down Expand Up @@ -71,107 +72,126 @@ class _TextRecordScreenState extends State<TextRecordScreen> {
create: (context) => NFCNotifier(),
child: Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
centerTitle: false,
backgroundColor: AppColors.backgroundColor2,
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: SvgPicture.asset(
'assets/arrow_left.svg',
fit: BoxFit.scaleDown,
),
),
title: Text(
'Text Record',
style: GoogleFonts.inter(
color: AppColors.primaryTextColor,
fontSize: 20.0,
fontWeight: FontWeight.w700,
),
'Write To NFC Tag',
style: AppTextStyle.alertDialogHeading,
),
),
body: Padding(
body: SingleChildScrollView(
padding: AllPadding.padding16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
children: [
Text(
'Enter Text Record',
style: GoogleFonts.inter(
color: AppColors.primaryTextColor,
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
'Type or paste the text you want to store on the NFC Tag and select ‘’Write Data’’ below.',
style: AppTextStyle.bodyText,
),
const YGap(value: 16.0),
SizedBox(
height: 121.0,
child: TextField(
controller: controller,
maxLines: 4, // Allow up to 3 lines of text
// minLines: 4, // Ensure at least one line is visible
decoration: const InputDecoration(
alignLabelWithHint: true,
labelText: 'Enter text here',
// labelStyle: ,
border: OutlineInputBorder(
borderSide: BorderSide(color: AppColors.primaryColor),
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3), // changes position of shadow
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppColors.primaryColor,
],
),
child: Column(
children: [
TextField(
controller: controller,
maxLines: null,
minLines: 10,
decoration: InputDecoration(
alignLabelWithHint: true,
labelText: 'Enter text here',
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
constraints: BoxConstraints(
maxHeight: 300,
),
contentPadding: EdgeInsets.all(12.0),
),
),
constraints: BoxConstraints(
maxHeight: 121,
SizedBox(height: 8.0),
Divider(
color: AppColors.dividerColour,
thickness: 1,
),
SizedBox(height: 8.0),
Align(
alignment: Alignment.bottomRight,
child: IconButton(
icon:
SvgPicture.asset('assets/icons/svg/paste.svg'),
onPressed: () async {
final clipboardData =
await Clipboard.getData('text/plain');
if (clipboardData != null) {
controller.text = clipboardData.text ?? '';
}
},
),
),
),
],
),
),
],
),
const YGap(value: 16.0),
PrimaryButton(
onTap: () async {
if (_nfcEnabled) {
writeToNfc();
//save to history
List<HistoryModel> loadedHistoryList =
await AppSharedPreference().getHistoryList();
loadedHistoryList.add(HistoryModel(
language: "English",
date: DateTime.now(),
actualText: controller.text,
type: HistoryType.written));
await AppSharedPreference()
.saveHistoryList(loadedHistoryList);
} else {
showModalBottomSheet(
isDismissible: false,
context: context,
builder: (context) {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.4,
child: AppBottomsheet(
message:
"Failed to write data to the NFC tag. Please try again.",
title: "Write Operation Failed",
centerContent: SvgPicture.asset(
'assets/icons/svg/nfc_unavailable.svg'),
hasPrimaryButton: true,
primaryButtonText: 'Try Again',
primaryButtonOnTap: () {
Navigator.of(context).pop();
},
),
);
});
}
},
text: 'Add'),
const YGap(value: 70.0),
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.6,
child: PrimaryButton(
onTap: () async {
if (_nfcEnabled) {
writeToNfc();
//save to history
List<HistoryModel> loadedHistoryList =
await AppSharedPreference().getHistoryList();
loadedHistoryList.add(HistoryModel(
language: "English",
date: DateTime.now(),
actualText: controller.text,
type: HistoryType.written));
await AppSharedPreference()
.saveHistoryList(loadedHistoryList);
} else {
showModalBottomSheet(
isDismissible: false,
context: context,
builder: (context) {
return SizedBox(
height:
MediaQuery.of(context).size.height * 0.4,
child: AppBottomsheet(
message:
"Failed to write data to the NFC tag. Please try again.",
title: "Write Operation Failed",
centerContent: SvgPicture.asset(
'assets/icons/svg/nfc_unavailable.svg'),
hasPrimaryButton: true,
primaryButtonText: 'Try Again',
primaryButtonOnTap: () {
Navigator.of(context).pop();
},
),
);
});
}
},
text: 'Write Data'),
),
),
Consumer<NFCNotifier>(builder: (context, provider, _) {
if (provider.isProcessing) {
// return const CircularProgressIndicator();
Expand Down
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ packages:
dependency: "direct main"
description:
name: shared_preferences
sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180
sha256: c3f888ba2d659f3e75f4686112cc1e71f46177f74452d40d8307edc332296ead
url: "https://pub.dev"
source: hosted
version: "2.2.3"
version: "2.3.0"
shared_preferences_android:
dependency: transitive
description:
Expand Down Expand Up @@ -556,10 +556,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_web
sha256: d762709c2bbe80626ecc819143013cc820fa49ca5e363620ee20a8b15a3e3daf
sha256: "3a293170d4d9403c3254ee05b84e62e8a9b3c5808ebd17de6a33fe9ea6457936"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
version: "2.4.0"
shared_preferences_windows:
dependency: transitive
description:
Expand Down Expand Up @@ -705,10 +705,10 @@ packages:
dependency: transitive
description:
name: video_player_web
sha256: "8e9cb7fe94e49490e67bbc15149691792b58a0ade31b32e3f3688d104a0e057b"
sha256: ff4d69a6614b03f055397c27a71c9d3ddea2b2a23d71b2ba0164f59ca32b8fe2
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.3.1"
vm_service:
dependency: transitive
description:
Expand Down

0 comments on commit dfec869

Please sign in to comment.