diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index d35dde3..1f0cdd9 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]} \ No newline at end of file +{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_blue","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]} \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index a080324..ff2f6b5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -8,7 +8,7 @@ FlutterApplication and put your custom class here. --> ( + home: //Home(), + StreamBuilder( stream: FlutterBlue.instance.state, initialData: BluetoothState.unknown, builder: (c, snapshot) { @@ -26,7 +25,7 @@ class OpenLightApp extends StatelessWidget { return WifiSetter(); } return BluetoothOffScreen(state: state); - }),*/ + }), theme: lightTheme, // darkTheme: darkTheme ); diff --git a/lib/screens/wifi_setter.dart b/lib/screens/wifi_setter.dart index 08aeb01..19e70a7 100644 --- a/lib/screens/wifi_setter.dart +++ b/lib/screens/wifi_setter.dart @@ -3,6 +3,8 @@ import 'dart:convert' show utf8, json; import 'package:flutter/material.dart'; import 'package:flutter_blue/flutter_blue.dart'; +import 'package:loading/indicator/line_scale_pulse_out_indicator.dart'; +import 'package:loading/loading.dart'; @@ -15,21 +17,26 @@ class _WifiSetterState extends State { final String serviceUUID = "4fafc201-1fb5-459e-8fcc-c5c9c331914b"; final String characteristicUUID = "beb5483e-36e1-4688-b7f5-ea07361b26a8"; - final String targetDeviceName = "ALINE"; + final String targetDeviceName = "aline"; FlutterBlue flutterBlue = FlutterBlue.instance; StreamSubscription scanSubscription; BluetoothDevice targetDevice; BluetoothCharacteristic targetCharacteristic; + BluetoothDeviceState targetDeviceState; + List connectionTexts = [ + "Searching for your light", + "Did you plug your aline in?", + "Still looking..." + ]; String connectionText = ""; - String connectionStatus = ""; + bool gotJson = false; String wifiString; Map wifiMap; Stream> streamFromBle; - @override void initState() { @@ -37,68 +44,63 @@ class _WifiSetterState extends State { startScan(); } - // start scan for BLE - void startScan() { - setState(() { - connectionText = "Start Scanning"; + + + void _deviceStateSubscription() { + targetDevice.state.listen((s) { + setState(() { + targetDeviceState = s; + }); }); + } + /// Start scan for BLE + void startScan() { + + // TODO: ADD TIMER FOR THE TEXT SWAP + scanSubscription = flutterBlue.scan().listen((scanResult) { - print('scanning..,'); - print(scanResult.device.name); + // print('scanning...'); + if (scanResult.device.name.contains(targetDeviceName)) { stopScan(); - setState(() { - connectionText = "Found Target Device"; - }); - targetDevice = scanResult.device; + + // Check device state + _deviceStateSubscription(); connectToDevice(); } }, onDone: () => stopScan()); } - // stop scanning + /// Stop scanning void stopScan() { scanSubscription?.cancel(); scanSubscription = null; } - // connect to device + /// Connect to device void connectToDevice() async { if (targetDevice == null) { return; } - setState(() { - connectionText = "Device Connecting"; - }); - await targetDevice.connect(); - setState(() { - connectionText = "Device Connected"; - connectionStatus = "connected"; - }); - discoverServices(); } - // disconnect from device + /// Disconnect from device void disconnectFromDeivce() { if (targetDevice == null) { return; } targetDevice.disconnect(); - - setState(() { - connectionText = "Device Disconnected"; - }); } - // discover services and connect to pre-defined service if available + /// Discover services and connect to pre-defined service if available void discoverServices() async { if (targetDevice == null) { return; @@ -110,15 +112,12 @@ class _WifiSetterState extends State { service.characteristics.forEach((characteristics) { if (characteristics.uuid.toString() == characteristicUUID) { targetCharacteristic = characteristics; - setState(() { - connectionText = "All Ready with ${targetDevice.name}"; - }); - + + // Getting wifi networks targetCharacteristic.setNotifyValue(true); streamFromBle = targetCharacteristic.value; streamFromBle.listen((data) { if(data != null && data.isNotEmpty) { - //print(utf8.decode(data)); mapWiFiNetworks(data); } }); @@ -140,6 +139,7 @@ class _WifiSetterState extends State { } else if(currentString == "@@end@@") { setState(() { wifiMap = json.decode(wifiString); + gotJson = true; }); } else { setState(() { @@ -173,19 +173,95 @@ class _WifiSetterState extends State { @override Widget build(BuildContext context) { + + print(targetDeviceState); + return Scaffold( - appBar: AppBar( - title: Text(connectionText), - ), + appBar: PreferredSize( + preferredSize: Size.fromHeight(120.0), + child: Container( + child: Padding( + padding: EdgeInsets.only(top: 56.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Image.asset( + 'assets/logo_a_light.png', + fit: BoxFit.contain, + height: 40, + ), + ], + )), + ), + ), body: Container( - child: targetCharacteristic == null - ? Center( - child: Text( - connectionText, - style: TextStyle(fontSize: 34, color: Colors.red), - ), - ) - : Column( + margin: EdgeInsets.only( + top: 100.0 + ), + child: targetDeviceState == BluetoothDeviceState.connected + ? ListView.builder( + itemCount: gotJson ? wifiMap["networks"].length : 0 , + itemBuilder: (BuildContext context, int index) { + + if(!gotJson) { + return SearchingForBluetooth(); + } + + print(wifiMap["networks"][index]["ssid"]); + + return GestureDetector( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text(wifiMap["networks"][index]["ssid"]), + Text(wifiMap["networks"][index]["rssi"].toString()), + Text(wifiMap["networks"][index]["encryption"].toString()), + ], + ), + ); + + }, + ) + : SearchingForBluetooth() + ), + ); + + } +} + +class SearchingForBluetooth extends StatelessWidget { + const SearchingForBluetooth({ + Key key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + height: 200.0, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Loading( + indicator: LineScalePulseOutIndicator(), + size: 80.0, + color: Theme.of(context).primaryColorLight, + ), + ), + SizedBox(height: 20.0 ), + Text( + "Searching for your light", + style: Theme.of(context).textTheme.title, + ) + ], + ), + ); + } +} + + +/* + Column( children: [ Padding( padding: const EdgeInsets.all(16), @@ -210,7 +286,7 @@ class _WifiSetterState extends State { ), ) ], - )), - ); - } -} \ No newline at end of file + ) + */ + + \ No newline at end of file diff --git a/lib/utils/themes.dart b/lib/utils/themes.dart index 4a4e558..6b8a22f 100644 --- a/lib/utils/themes.dart +++ b/lib/utils/themes.dart @@ -16,17 +16,25 @@ final Color _accentColor = new Color(0xffFFBE61); /// Light Theme final ThemeData lightTheme = ThemeData( primaryColor: _baseColorLight, + primaryColorLight: _shadowColorLightBright, + primaryColorDark: _shadowColorLightDark, accentColor: _accentColor, scaffoldBackgroundColor: _baseColorLight, - dialogBackgroundColor: _baseColorLight + dialogBackgroundColor: _baseColorLight, + fontFamily: 'Poppins', + textTheme: TextTheme( + title: TextStyle(color: _shadowColorLightDark), + ) ); /// Dark Theme final ThemeData darkTheme = ThemeData.dark().copyWith( primaryColor: _baseColorDark, + primaryColorLight: _shadowColorDarkBright, + primaryColorDark: _shadowColorDarkDark, accentColor: _accentColor, scaffoldBackgroundColor: _baseColorDark, - dialogBackgroundColor: _baseColorDark + dialogBackgroundColor: _baseColorDark, ); diff --git a/pubspec.lock b/pubspec.lock index 3e95c78..ecd0812 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -93,6 +93,27 @@ packages: description: flutter source: sdk version: "0.0.0" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.5" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.0+4" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.3" image: dependency: transitive description: @@ -100,6 +121,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.4" + loading: + dependency: "direct main" + description: + name: loading + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" matcher: dependency: transitive description: @@ -128,6 +156,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.4" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" pedantic: dependency: transitive description: @@ -142,6 +177,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" protobuf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5b5eed7..5e72002 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: flutter_blue: 0.6.2 shared_preferences: ^0.5.6+1 neumorphic: ^0.0.2 + loading: ^1.0.2 + google_fonts: ^0.3.5 # dynamic_theme: ^1.0.1 dev_dependencies: @@ -54,17 +56,13 @@ flutter: # "family" key with the font family name, and a "fonts" key with a # list giving the asset and other descriptors for the font. For # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages + fonts: + - family: Poppins + fonts: + - asset: fonts/Poppins-Regular.ttf + - asset: fonts/Poppins-light.ttf + weight: 300 + - asset: fonts/Poppins-SemiBold.ttf + weight: 600 + - asset: fonts/Poppins-Bold.ttf + weight: 700