Skip to content

Commit

Permalink
refs #10,#21,#5 More cleanup, get splash layout looking ok, add scan
Browse files Browse the repository at this point in the history
Scan does nothing.  Need to add list to UI
  • Loading branch information
truedat101 committed Jan 28, 2024
1 parent fefc900 commit b6e8745
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
16 changes: 9 additions & 7 deletions magnet_app/lib/app_state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AppState extends BLEProvider {

Timer(const Duration(seconds: 5), () {
// scanAndConnectToDevice();
print("Move to home scree");
print("Move to home screen");
app_screen = "home";
notifyListeners();
});
Expand Down Expand Up @@ -101,7 +101,7 @@ class AppState extends BLEProvider {
print("examinging new device");
print("---------------------");
if (device.id == deviceId) {
print("--------------> Found Halo!!!!");
print("--------------> Found match!!!!");
} else {
print(device.name +
" " +
Expand All @@ -110,8 +110,8 @@ class AppState extends BLEProvider {
device.id);
}
// print(device.id);
if (device.name == "Halo") {
haloDevice = device;
if (device.name == "target") {
discoveredDevice = device;
foundDeviceWaitingToConnect = true;
notifyListeners();
print("Halo is found");
Expand All @@ -132,7 +132,8 @@ class AppState extends BLEProvider {
scanStarted = false;

if (!connected) {
_bleUpdateScreenState("disconnected");
// XXX TODO: update screen at end of scan
// _bleUpdateScreenState("disconnected");
}

notifyListeners();
Expand All @@ -153,7 +154,8 @@ class AppState extends BLEProvider {

void scanAndConnectToDevice() async {
//Update Screen
_bleUpdateScreenState("connecting");
// XXX TODO: show progress on scan
// _bleUpdateScreenState("connecting");

startScan();

Expand All @@ -167,7 +169,7 @@ class AppState extends BLEProvider {
void _connectToDevice() async {
Stream<ConnectionStateUpdate> _currentConnnectionStream =
ble.connectToDevice(
id: haloDevice.id,
id: discoveredDevice.id,
servicesWithCharacteristicsToDiscover: {
serviceUuid: [txUUID, rxUUID]
},
Expand Down
10 changes: 8 additions & 2 deletions magnet_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ class MyApp extends StatelessWidget {

class MyHomePage extends StatelessWidget {
MyHomePage({super.key});

Widget build(BuildContext context) {
final appState = Provider.of<AppState>(context, listen: false);

return Scaffold(
floatingActionButton: NeumorphicFloatingActionButton(
child: Icon(Icons.add, size: 30),
onPressed: () {},
onPressed: () {
appState.scanAndConnectToDevice();
},
),
backgroundColor: NeumorphicTheme.baseColor(context),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
/*
NeumorphicButton(
onPressed: () {
print("onClick");
Expand Down Expand Up @@ -120,6 +125,7 @@ class MyHomePage extends StatelessWidget {
"Go to full sample",
style: TextStyle(color: _textColor(context)),
)),
*/
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion magnet_app/lib/provider/ble_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BLEProvider extends ChangeNotifier {
bool connected = false;

//Bluetooth Related Variables
late DiscoveredDevice haloDevice;
late DiscoveredDevice discoveredDevice;
final FlutterReactiveBle ble = FlutterReactiveBle();
late StreamSubscription<DiscoveredDevice> scanDeviceStream;
late QualifiedCharacteristic rxCharacterisitic, txCharacterisitic;
Expand Down
109 changes: 109 additions & 0 deletions magnet_app/lib/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,114 @@ class _SplashPageWidgetState extends State<SplashPageWidget> {
super.initState();
// _navigatetohome();
}
Widget _letter(String letter) {
return Text(letter,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
fontFamily: 'Samsung',
fontSize: 62));
}

@override
Widget build(BuildContext context) {
return Scaffold(
/*
floatingActionButton: NeumorphicFloatingActionButton(
child: const Icon(Icons.add, size: 30),
onPressed: () {},
),*/
backgroundColor: NeumorphicTheme.baseColor(context),
appBar: AppBar(
centerTitle: true,
toolbarHeight: 150,
backgroundColor: NeumorphicTheme.baseColor(context),
title: _letter("MagNET"),
// title: Image.asset('assets/images/mobilelogo.png'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 50.0),
child: Image(image: AssetImage('assets/images/magnet_splash.jpg')))
/*
NeumorphicButton(
onPressed: () {
print("onClick");
},
style: const NeumorphicStyle(
shape: NeumorphicShape.flat,
boxShape: NeumorphicBoxShape.circle(),
),
padding: const EdgeInsets.all(12.0),
child: Icon(
Icons.favorite_border,
color: _iconsColor(context),
),
),
NeumorphicButton(
margin: const EdgeInsets.only(top: 12),
onPressed: () {
NeumorphicTheme.of(context)!.themeMode =
NeumorphicTheme.isUsingDark(context)
? ThemeMode.light
: ThemeMode.dark;
},
style: NeumorphicStyle(
shape: NeumorphicShape.flat,
boxShape:
NeumorphicBoxShape.roundRect(BorderRadius.circular(8)),
),
padding: const EdgeInsets.all(12.0),
child: Text(
"Toggle Theme",
style: TextStyle(color: _textColor(context)),
)),
NeumorphicButton(
margin: const EdgeInsets.only(top: 12),
onPressed: () {
Navigator.of(context)
.pushReplacement(MaterialPageRoute(builder: (context) {
return FullSampleHomePage();
}));
},
style: NeumorphicStyle(
shape: NeumorphicShape.flat,
boxShape:
NeumorphicBoxShape.roundRect(BorderRadius.circular(8)),
//border: NeumorphicBorder()
),
padding: const EdgeInsets.all(12.0),
child: Text(
"Go to full sample",
style: TextStyle(color: _textColor(context)),
)),
*/
],
),
),
);
}

Color? _iconsColor(BuildContext context) {
final theme = NeumorphicTheme.of(context);
if (theme!.isUsingDark) {
return theme.current!.accentColor;
} else {
return null;
}
}

Color _textColor(BuildContext context) {
if (NeumorphicTheme.isUsingDark(context)) {
return Colors.white;
} else {
return Colors.black;
}
}
/*
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -45,4 +152,6 @@ class _SplashPageWidgetState extends State<SplashPageWidget> {
)),
);
}
*/
}

0 comments on commit b6e8745

Please sign in to comment.