From b6e87458463ed4a5908ac0b2d4d75ef22c40c35b Mon Sep 17 00:00:00 2001 From: David J Kordsmeier Date: Sat, 27 Jan 2024 23:42:56 -0800 Subject: [PATCH] refs #10,#21,#5 More cleanup, get splash layout looking ok, add scan Scan does nothing. Need to add list to UI --- magnet_app/lib/app_state_model.dart | 16 ++-- magnet_app/lib/main.dart | 10 +- magnet_app/lib/provider/ble_provider.dart | 2 +- magnet_app/lib/splash_page.dart | 109 ++++++++++++++++++++++ 4 files changed, 127 insertions(+), 10 deletions(-) diff --git a/magnet_app/lib/app_state_model.dart b/magnet_app/lib/app_state_model.dart index 998cb28..72b5976 100644 --- a/magnet_app/lib/app_state_model.dart +++ b/magnet_app/lib/app_state_model.dart @@ -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(); }); @@ -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 + " " + @@ -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"); @@ -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(); @@ -153,7 +154,8 @@ class AppState extends BLEProvider { void scanAndConnectToDevice() async { //Update Screen - _bleUpdateScreenState("connecting"); + // XXX TODO: show progress on scan + // _bleUpdateScreenState("connecting"); startScan(); @@ -167,7 +169,7 @@ class AppState extends BLEProvider { void _connectToDevice() async { Stream _currentConnnectionStream = ble.connectToDevice( - id: haloDevice.id, + id: discoveredDevice.id, servicesWithCharacteristicsToDiscover: { serviceUuid: [txUUID, rxUUID] }, diff --git a/magnet_app/lib/main.dart b/magnet_app/lib/main.dart index 7733d2c..05ee5ff 100644 --- a/magnet_app/lib/main.dart +++ b/magnet_app/lib/main.dart @@ -57,18 +57,23 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatelessWidget { MyHomePage({super.key}); - + Widget build(BuildContext context) { + final appState = Provider.of(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: [ + /* NeumorphicButton( onPressed: () { print("onClick"); @@ -120,6 +125,7 @@ class MyHomePage extends StatelessWidget { "Go to full sample", style: TextStyle(color: _textColor(context)), )), + */ ], ), ), diff --git a/magnet_app/lib/provider/ble_provider.dart b/magnet_app/lib/provider/ble_provider.dart index 4e77cb0..67c1676 100644 --- a/magnet_app/lib/provider/ble_provider.dart +++ b/magnet_app/lib/provider/ble_provider.dart @@ -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 scanDeviceStream; late QualifiedCharacteristic rxCharacterisitic, txCharacterisitic; diff --git a/magnet_app/lib/splash_page.dart b/magnet_app/lib/splash_page.dart index f94a63c..104b5d4 100644 --- a/magnet_app/lib/splash_page.dart +++ b/magnet_app/lib/splash_page.dart @@ -23,7 +23,114 @@ class _SplashPageWidgetState extends State { 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: [ + 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( @@ -45,4 +152,6 @@ class _SplashPageWidgetState extends State { )), ); } + */ } +