Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature whastapp instructions update #39

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/pages/add_bridge/add_bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,6 @@ class BotController extends State<AddBridge> {
}
}

/// Check last received message for WhatsApp
/// Check last received message for WhatsApp
void _onWhatsAppMessage(
String directChat,
Expand Down
14 changes: 8 additions & 6 deletions lib/pages/add_bridge/connection_bridge_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ Future<void> connectToWhatsApp(
),
TextButton(
onPressed: () async {
await whatsAppLoginFunction(
context: context,
formKey: formKey,
phoneNumber: controller.text,
botConnection: botConnection,
);
if (controller.text.isNotEmpty) {
await whatsAppLoginFunction(
context: context,
formKey: formKey,
phoneNumber: controller.text,
botConnection: botConnection,
);
}
},
child: Text(
L10n.of(context)!.login,
Expand Down
140 changes: 54 additions & 86 deletions lib/pages/add_bridge/qr_code_connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ class QRCodeConnectPage extends StatefulWidget {

class _QRCodeConnectPageState extends State<QRCodeConnectPage> {
late Future<String> responseFuture;
bool _isDialogShown = false;

@override
void initState() {
super.initState();

widget.botConnection.continueProcess = true;

responseFuture = widget.botConnection.fetchDataWhatsApp();
}

Expand All @@ -41,6 +40,12 @@ class _QRCodeConnectPageState extends State<QRCodeConnectPage> {
super.dispose();
}

void _setDialogShown() {
setState(() {
_isDialogShown = true;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -64,6 +69,8 @@ class _QRCodeConnectPageState extends State<QRCodeConnectPage> {
QRFutureBuilder(
responseFuture: responseFuture,
network: widget.socialNetwork,
isDialogShown: _isDialogShown,
setDialogShown: _setDialogShown,
),
],
),
Expand All @@ -90,27 +97,21 @@ class QRExplanation extends StatelessWidget {
Widget build(BuildContext context) {
Widget qrWidget;

String qrExplainOne = "";
String qrExplainTwo = "";
String qrExplainThree = "";
String qrExplainFour = "";
String qrExplainFive = "";
String qrExplainSix = "";
String qrExplainSeven = "";
String qrExplainEight = "";
String qrExplainNine = "";
List<String> qrExplains = [];

switch (network.name) {
case "WhatsApp":
qrExplainOne = L10n.of(context)!.whatsAppQrExplainOne;
qrExplainTwo = L10n.of(context)!.whatsAppQrExplainTwo;
qrExplainThree = L10n.of(context)!.whatsAppQrExplainTree;
qrExplainFour = L10n.of(context)!.whatsAppQrExplainFour;
qrExplainFive = L10n.of(context)!.whatsAppQrExplainFive;
qrExplainSix = L10n.of(context)!.whatsAppQrExplainSix;
qrExplainSeven = L10n.of(context)!.whatsAppQrExplainSeven;
qrExplainEight = L10n.of(context)!.whatsAppQrExplainEight;
qrExplainNine = L10n.of(context)!.whatsAppQrExplainNine;
qrExplains = [
L10n.of(context)!.whatsAppQrExplainOne,
L10n.of(context)!.whatsAppQrExplainTwo,
L10n.of(context)!.whatsAppQrExplainTree,
L10n.of(context)!.whatsAppQrExplainFour,
L10n.of(context)!.whatsAppQrExplainFive,
L10n.of(context)!.whatsAppQrExplainSix,
L10n.of(context)!.whatsAppQrExplainSeven,
L10n.of(context)!.whatsAppQrExplainEight,
L10n.of(context)!.whatsAppQrExplainNine,
];

qrWidget = QrImageView(
data: qrCode,
Expand All @@ -129,30 +130,13 @@ class QRExplanation extends StatelessWidget {

return Column(
children: [
Text(
qrExplainOne,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Text(
qrExplainTwo,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
Text(
qrExplainThree,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
Text(
qrExplainFour,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
Text(
qrExplainFive,
style: const TextStyle(fontSize: 16),
),
...qrExplains.take(5).map((text) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Text(
text,
style: const TextStyle(fontSize: 16),
),
)),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splendid

const SizedBox(height: 8),
ElevatedButton(
onPressed: () {
Expand All @@ -165,7 +149,7 @@ class QRExplanation extends StatelessWidget {
padding: const EdgeInsets.all(2.0),
child: Text(
code,
style: TextStyle(
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
decoration: null,
Expand All @@ -179,29 +163,14 @@ class QRExplanation extends StatelessWidget {
color: Colors.grey,
height: 20,
),
Text(
qrExplainSix,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
qrExplainSeven,
style: const TextStyle(fontSize: 16),
),
Text(
qrExplainEight,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
...qrExplains.skip(5).map(
(text) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Text(text,
style: const TextStyle(fontSize: 16),
textAlign: TextAlign.center),
),
),
],
),
const SizedBox(height: 8),
Text(
qrExplainNine,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 8),
qrWidget,
],
Expand All @@ -213,11 +182,15 @@ class QRExplanation extends StatelessWidget {
class QRFutureBuilder extends StatelessWidget {
final Future<String> responseFuture;
final SocialNetwork network;
final bool isDialogShown;
final VoidCallback setDialogShown;

const QRFutureBuilder({
super.key,
required this.responseFuture,
required this.network,
required this.isDialogShown,
required this.setDialogShown,
});

@override
Expand All @@ -230,33 +203,25 @@ class QRFutureBuilder extends StatelessWidget {
} else if (snapshot.hasError) {
return Text('${L10n.of(context)!.err_} ${snapshot.error}');
} else {
return buildAlertDialog(context, snapshot.data as String, network);
if (!isDialogShown) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (snapshot.data == "success") {
showSuccessDialog(context, network);
} else if (snapshot.data == "loginTimedOut") {
showTimeoutDialog(context, network);
}
});
}
return Container();
}
},
);
}

// AlertDialog displayed when an error or success occurs, listening directly to the response
Widget buildAlertDialog(
BuildContext context, String result, SocialNetwork network) {
if (result == "success") {
Future.microtask(() {
// Call function to display success dialog box
showSuccessDialog(context, network);
});
} else if (result == "loginTimedOut") {
Future.microtask(() {
// Call the function to display the "Elapsed time" dialog box
showTimeoutDialog(context, network);
});
}

return Container();
}

// showDialog of a success message when connecting and updating socialNetwork
Future<void> showSuccessDialog(
BuildContext context, SocialNetwork network) async {
setDialogShown();
await showDialog(
context: context,
builder: (BuildContext context) {
Expand All @@ -276,6 +241,7 @@ class QRFutureBuilder extends StatelessWidget {
.connected = true;

Navigator.of(context).pop();
Navigator.of(context).pop();
},
child: Text(
L10n.of(context)!.ok,
Expand All @@ -290,6 +256,7 @@ class QRFutureBuilder extends StatelessWidget {
// showDialog of elapsed time error message
Future<void> showTimeoutDialog(
BuildContext context, SocialNetwork network) async {
setDialogShown();
await showDialog(
context: context,
builder: (BuildContext context) {
Expand All @@ -304,6 +271,7 @@ class QRFutureBuilder extends StatelessWidget {
TextButton(
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pop();
},
child: Text(
L10n.of(context)!.ok,
Expand Down
Loading