Skip to content

Commit 2e92054

Browse files
Vidhijain20AsCress
andauthored
feat: added Connect Device screen (#2691)
Co-authored-by: Anashuman Singh <[email protected]>
1 parent 1a75e38 commit 2e92054

File tree

7 files changed

+282
-5
lines changed

7 files changed

+282
-5
lines changed
1.75 KB
Loading
1.86 KB
Loading

lib/constants.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ List<String> channelEntries = [
8585
'CH3',
8686
'MIC',
8787
];
88+
89+
String connectDevice = 'Connect Device';
90+
String deviceConnected = 'Device Connected Successfully';
91+
String noDeviceFound = 'No USB Device Found';
92+
List<String> stepsToConnect = [
93+
'Steps to connect the PSLab Device',
94+
'1. Connect a micro USB(Mini B) to PSLab',
95+
'2. Connect the other end of the micro USB cable to a OTG',
96+
'3. Connect the OTG to the phone'
97+
];
98+
String bluetoothWifiConnection = 'Connect using Bluetooth or Wi-Fi';
99+
String bluetooth = 'BLUETOOTH';
100+
String wifi = 'WIFI';
101+
String whatisPslab = 'What is PSLab Device?';
102+
String pslabUrl = 'https://pslab.io';

lib/view/connect_device_screen.dart

Lines changed: 190 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import 'package:flutter/cupertino.dart';
1+
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
3+
import 'package:pslab/constants.dart';
4+
import 'package:pslab/providers/board_state_provider.dart';
5+
import 'package:pslab/view/widgets/main_scaffold_widget.dart';
6+
import 'package:url_launcher/url_launcher.dart';
27

38
class ConnectDeviceScreen extends StatefulWidget {
49
const ConnectDeviceScreen({super.key});
10+
final String iconUsbDisconnected =
11+
'assets/icons/icons_usb_disconnected_100.png';
12+
final String iconUsbConnected = 'assets/icons/icons8_usb_connected_100.png';
513

614
@override
715
State<StatefulWidget> createState() => _HomeScreenState();
@@ -10,7 +18,186 @@ class ConnectDeviceScreen extends StatefulWidget {
1018
class _HomeScreenState extends State<ConnectDeviceScreen> {
1119
@override
1220
Widget build(BuildContext context) {
13-
// TODO: implement build
14-
throw UnimplementedError();
21+
return MainScaffold(
22+
index: 2,
23+
title: connectDevice,
24+
body: Consumer<BoardStateProvider>(
25+
builder: (context, provider, _) {
26+
return SafeArea(
27+
child: Center(
28+
child: SingleChildScrollView(
29+
child: Column(
30+
mainAxisAlignment: MainAxisAlignment.center,
31+
children: [
32+
const SizedBox(
33+
height: 10,
34+
),
35+
Center(
36+
child: Image.asset(
37+
provider.pslabIsConnected
38+
? widget.iconUsbConnected
39+
: widget.iconUsbDisconnected,
40+
width: 80,
41+
height: 80,
42+
),
43+
),
44+
Center(
45+
child: Container(
46+
margin: const EdgeInsets.only(
47+
top: 20, bottom: 60, left: 40, right: 40),
48+
child: Text(
49+
provider.pslabIsConnected
50+
? '$deviceConnected\n\n${provider.pslabVersionID}'
51+
: noDeviceFound,
52+
textAlign: TextAlign.center,
53+
style: TextStyle(
54+
fontSize: 20,
55+
color: Colors.blueGrey[600],
56+
fontWeight: FontWeight.bold,
57+
),
58+
),
59+
),
60+
),
61+
Visibility(
62+
visible: provider.pslabIsConnected ? false : true,
63+
child: Container(
64+
margin: const EdgeInsets.only(
65+
left: 40, right: 40, bottom: 20),
66+
child: Column(
67+
crossAxisAlignment: CrossAxisAlignment.center,
68+
children: [
69+
Text(
70+
stepsToConnect[0],
71+
textAlign: TextAlign.center,
72+
style: const TextStyle(
73+
decoration: TextDecoration.underline,
74+
color: Colors.black,
75+
fontSize: 18,
76+
fontWeight: FontWeight.bold,
77+
),
78+
),
79+
const SizedBox(height: 20),
80+
Text(
81+
stepsToConnect[1],
82+
style: const TextStyle(
83+
fontSize: 16,
84+
color: Colors.black,
85+
),
86+
),
87+
Text(
88+
stepsToConnect[2],
89+
style: const TextStyle(
90+
fontSize: 16,
91+
color: Colors.black,
92+
),
93+
),
94+
Text(
95+
stepsToConnect[3],
96+
style: const TextStyle(
97+
fontSize: 16,
98+
color: Colors.black,
99+
),
100+
),
101+
],
102+
),
103+
),
104+
),
105+
Visibility(
106+
visible: provider.pslabIsConnected ? false : true,
107+
child: Center(
108+
child: Text(
109+
bluetoothWifiConnection,
110+
style: const TextStyle(
111+
color: Colors.black,
112+
fontSize: 14,
113+
),
114+
),
115+
),
116+
),
117+
Visibility(
118+
visible: provider.pslabIsConnected ? false : true,
119+
child: Container(
120+
margin: const EdgeInsets.only(top: 15),
121+
child: Row(
122+
mainAxisAlignment: MainAxisAlignment.center,
123+
mainAxisSize: MainAxisSize.min,
124+
children: [
125+
ElevatedButton(
126+
style: ElevatedButton.styleFrom(
127+
shape: const RoundedRectangleBorder(
128+
borderRadius: BorderRadius.zero,
129+
),
130+
backgroundColor: const Color(0xFFD32F2F),
131+
foregroundColor: Colors.white,
132+
),
133+
onPressed: () {},
134+
child: Padding(
135+
padding: const EdgeInsets.all(10),
136+
child: Text(
137+
bluetooth,
138+
style: const TextStyle(color: Colors.white),
139+
),
140+
),
141+
),
142+
const SizedBox(width: 20),
143+
ElevatedButton(
144+
style: ElevatedButton.styleFrom(
145+
shape: const RoundedRectangleBorder(
146+
borderRadius: BorderRadius.zero,
147+
),
148+
backgroundColor: const Color(0xFFD32F2F),
149+
foregroundColor: Colors.white,
150+
),
151+
onPressed: () {},
152+
child: Padding(
153+
padding: const EdgeInsets.all(10),
154+
child: Text(
155+
wifi,
156+
style: const TextStyle(color: Colors.white),
157+
),
158+
),
159+
),
160+
],
161+
),
162+
),
163+
),
164+
Container(
165+
margin:
166+
const EdgeInsets.only(top: 30, left: 120, right: 120),
167+
child: const Divider(color: Colors.grey, height: 1),
168+
),
169+
Center(
170+
child: Container(
171+
margin: const EdgeInsets.only(top: 20),
172+
padding: const EdgeInsets.all(10),
173+
child: GestureDetector(
174+
onTap: () async {
175+
await launchUrl(Uri.parse(pslabUrl));
176+
},
177+
child: Text(
178+
whatisPslab,
179+
style: const TextStyle(
180+
decoration: TextDecoration.underline,
181+
decorationThickness: 1,
182+
decorationColor: Color(0xFFD32F2F),
183+
color: Color(0xFFD32F2F),
184+
fontWeight: FontWeight.bold,
185+
fontSize: 20,
186+
),
187+
),
188+
),
189+
),
190+
),
191+
const SizedBox(
192+
height: 10,
193+
),
194+
],
195+
),
196+
),
197+
),
198+
);
199+
},
200+
),
201+
);
15202
}
16203
}

lib/view/widgets/navigation_drawer.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ class _NavDrawerState extends State<NavDrawer> {
123123
),
124124
),
125125
onTap: () {
126-
/**/
126+
if (Navigator.canPop(context) &&
127+
ModalRoute.of(context)?.settings.name == '/connectDevice') {
128+
Navigator.popUntil(
129+
context, ModalRoute.withName('/connectDevice'));
130+
} else {
131+
Navigator.pushNamedAndRemoveUntil(
132+
context,
133+
'/connectDevice',
134+
(route) => route.isFirst,
135+
);
136+
}
127137
},
128138
),
129139
ListTile(

pubspec.lock

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,70 @@ packages:
462462
url: "https://pub.dev"
463463
source: hosted
464464
version: "1.4.0"
465+
url_launcher:
466+
dependency: "direct main"
467+
description:
468+
name: url_launcher
469+
sha256: "9d06212b1362abc2f0f0d78e6f09f726608c74e3b9462e8368bb03314aa8d603"
470+
url: "https://pub.dev"
471+
source: hosted
472+
version: "6.3.1"
473+
url_launcher_android:
474+
dependency: transitive
475+
description:
476+
name: url_launcher_android
477+
sha256: "8582d7f6fe14d2652b4c45c9b6c14c0b678c2af2d083a11b604caeba51930d79"
478+
url: "https://pub.dev"
479+
source: hosted
480+
version: "6.3.16"
481+
url_launcher_ios:
482+
dependency: transitive
483+
description:
484+
name: url_launcher_ios
485+
sha256: "7f2022359d4c099eea7df3fdf739f7d3d3b9faf3166fb1dd390775176e0b76cb"
486+
url: "https://pub.dev"
487+
source: hosted
488+
version: "6.3.3"
489+
url_launcher_linux:
490+
dependency: transitive
491+
description:
492+
name: url_launcher_linux
493+
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
494+
url: "https://pub.dev"
495+
source: hosted
496+
version: "3.2.1"
497+
url_launcher_macos:
498+
dependency: transitive
499+
description:
500+
name: url_launcher_macos
501+
sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2"
502+
url: "https://pub.dev"
503+
source: hosted
504+
version: "3.2.2"
505+
url_launcher_platform_interface:
506+
dependency: transitive
507+
description:
508+
name: url_launcher_platform_interface
509+
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
510+
url: "https://pub.dev"
511+
source: hosted
512+
version: "2.3.2"
513+
url_launcher_web:
514+
dependency: transitive
515+
description:
516+
name: url_launcher_web
517+
sha256: "4bd2b7b4dc4d4d0b94e5babfffbca8eac1a126c7f3d6ecbc1a11013faa3abba2"
518+
url: "https://pub.dev"
519+
source: hosted
520+
version: "2.4.1"
521+
url_launcher_windows:
522+
dependency: transitive
523+
description:
524+
name: url_launcher_windows
525+
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
526+
url: "https://pub.dev"
527+
source: hosted
528+
version: "3.1.4"
465529
usb_serial:
466530
dependency: "direct main"
467531
description:
@@ -537,4 +601,4 @@ packages:
537601
version: "6.5.0"
538602
sdks:
539603
dart: ">=3.7.0-0 <4.0.0"
540-
flutter: ">=3.24.0"
604+
flutter: ">=3.27.0"

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies:
5151
data: ^0.13.0
5252
permission_handler: ^11.3.1
5353
logger: ^2.5.0
54+
url_launcher: ^6.3.1
5455

5556
dev_dependencies:
5657
flutter_test:

0 commit comments

Comments
 (0)