diff --git a/flutter_provisioning_for_iot/README.md b/flutter_provisioning_for_iot/README.md index f978d76..f52895a 100644 --- a/flutter_provisioning_for_iot/README.md +++ b/flutter_provisioning_for_iot/README.md @@ -14,3 +14,7 @@ A few resources to get you started if this is your first Flutter project: For help getting started with Flutter development, view the [online documentation](https://docs.flutter.dev/), which offers tutorials, samples, guidance on mobile development, and a full API reference. +
+To build this projekt with windows be sure to set in
+settings -> windows security -> for developers -> developer mode -> on + diff --git a/flutter_provisioning_for_iot/android/app/build.gradle b/flutter_provisioning_for_iot/android/app/build.gradle index a2d3a56..f070ee0 100644 --- a/flutter_provisioning_for_iot/android/app/build.gradle +++ b/flutter_provisioning_for_iot/android/app/build.gradle @@ -47,7 +47,7 @@ android { applicationId "com.example.flutter_provisioning_for_iot" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/flutter_provisioning_for_iot/android/app/src/main/AndroidManifest.xml b/flutter_provisioning_for_iot/android/app/src/main/AndroidManifest.xml index 3240b0d..4697b49 100644 --- a/flutter_provisioning_for_iot/android/app/src/main/AndroidManifest.xml +++ b/flutter_provisioning_for_iot/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,10 @@ + + + + - diff --git a/flutter_provisioning_for_iot/lib/BluetoothTest.dart b/flutter_provisioning_for_iot/lib/BluetoothTest.dart new file mode 100644 index 0000000..8bb3cc9 --- /dev/null +++ b/flutter_provisioning_for_iot/lib/BluetoothTest.dart @@ -0,0 +1,44 @@ +import 'package:flutter_blue/flutter_blue.dart'; +import 'package:flutter/material.dart'; +import 'dart:async'; +import 'dart:math'; + +import 'Sidebar.dart'; + +class BluetoothTest extends StatefulWidget { + const BluetoothTest({super.key}); + + @override + State createState() => _BluetoothTest(); +} + +class _BluetoothTest extends State { + FlutterBlue flutterBlue = FlutterBlue.instance; + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Bluetooth Test"), + ), + body: Center( + child: TextButton( + onPressed: () { + var subscription = flutterBlue.scanResults.listen((results) { + // do something with scan results + for (ScanResult r in results) { + String scan = '"${r.device.name} found! rssi: ${r.rssi}"'; + debugPrint(scan); + } + }); + // Stop scanning + flutterBlue.stopScan(); + + }, child: const Text("Scan Devices"), + ), + ), + drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods. + ); + } +} + + diff --git a/flutter_provisioning_for_iot/lib/MainPage.dart b/flutter_provisioning_for_iot/lib/MainPage.dart new file mode 100644 index 0000000..5e3aa88 --- /dev/null +++ b/flutter_provisioning_for_iot/lib/MainPage.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_provisioning_for_iot/Sidebar.dart'; +import 'package:flutter_blue/flutter_blue.dart'; + +class MainPage extends StatelessWidget { + const MainPage({super.key}); + + // This widget is the root of your application. + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Provisioning for IOT', + theme: ThemeData( + // This is the theme of your application. + // + // Try running your application with "flutter run". You'll see the + // application has a blue toolbar. Then, without quitting the app, try + // changing the primarySwatch below to Colors.green and then invoke + // "hot reload" (press "r" in the console where you ran "flutter run", + // or simply save your changes to "hot reload" in a Flutter IDE). + // Notice that the counter didn't reset back to zero; the application + // is not restarted. + primarySwatch: Colors.blue, + ), + home: const MyHomePage(title: 'Provisioning for IOT'), + ); + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + _counter++; + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods. + ); + } +} diff --git a/flutter_provisioning_for_iot/lib/Settings.dart b/flutter_provisioning_for_iot/lib/Settings.dart new file mode 100644 index 0000000..c9f6ffe --- /dev/null +++ b/flutter_provisioning_for_iot/lib/Settings.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import 'Sidebar.dart'; + +class Settings extends StatefulWidget { + const Settings({Key? key}) : super(key: key); + + static const initIp = ""; + + static var ip = initIp; + + static const initPort = ""; + + static var port = initPort; + + static SharedPreferences? preferencesInstance; + + @override + State createState() => _SettingsState(); + + /// Initializes the Settings with the correct Values from the last session + static Future initSettings() async { + } +} + +class _SettingsState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + // Here we take the value from the MyHomePage object that was created by + // the App.build method, and use it to set our appbar title. + title: const Text("Settings"), + ), + body: Center( + child: Column( + children: [ + TextFormField( + decoration: const InputDecoration( + labelText: "Address for the Classifier-Server"), + initialValue: Settings.ip, + onChanged: (String newValue) { + Settings.ip = newValue; + Settings.preferencesInstance?.setString("IP", newValue); + }, + ), + TextFormField( + decoration: const InputDecoration( + labelText: "Port for the Classifier-Server"), + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + initialValue: Settings.port, + onChanged: (String newValue) { + Settings.port = newValue; + Settings.preferencesInstance?.setString("Port", newValue); + }, + ) + ], + ), + ), + drawer: const Sidebar()); + } +} diff --git a/flutter_provisioning_for_iot/lib/Sidebar.dart b/flutter_provisioning_for_iot/lib/Sidebar.dart new file mode 100644 index 0000000..a80dbaa --- /dev/null +++ b/flutter_provisioning_for_iot/lib/Sidebar.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_provisioning_for_iot/BluetoothTest.dart'; +import 'MainPage.dart'; +import 'Settings.dart'; + +class Sidebar extends StatelessWidget { + const Sidebar({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Drawer( + child: ListView( + children: [ + const DrawerHeader( + decoration: BoxDecoration(color: Color(0xFF00844D)), + child: Text("Navigation"), + ), + ListTile( + title: const Text("Main Page"), + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) => const MainPage())); + }, + ), + ListTile( + title: const Text("Settings"), + onTap: () { + Navigator.push(context, + MaterialPageRoute(builder: (context) => const Settings())); + }, + ), + ListTile( + title: const Text("Bluetooth Test"), + onTap: () { + Navigator.push(context, MaterialPageRoute(builder: (context) => const BluetoothTest())); + }, + ), + + ], + ), + ); + } +} diff --git a/flutter_provisioning_for_iot/lib/main.dart b/flutter_provisioning_for_iot/lib/main.dart index e016029..95f9426 100644 --- a/flutter_provisioning_for_iot/lib/main.dart +++ b/flutter_provisioning_for_iot/lib/main.dart @@ -1,115 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_blue/flutter_blue.dart'; +import 'package:flutter_provisioning_for_iot/MainPage.dart'; void main() { - runApp(const MyApp()); + runApp(const MainPage()); } -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - // This widget is the root of your application. - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. - primarySwatch: Colors.blue, - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); - } -} diff --git a/flutter_provisioning_for_iot/pubspec.yaml b/flutter_provisioning_for_iot/pubspec.yaml index 95146cb..9395086 100644 --- a/flutter_provisioning_for_iot/pubspec.yaml +++ b/flutter_provisioning_for_iot/pubspec.yaml @@ -36,6 +36,9 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + flutter_blue: ^0.8.0 + shared_preferences: ^2.0.13 + dev_dependencies: flutter_test: diff --git a/flutter_provisioning_for_iot/test/widget_test.dart b/flutter_provisioning_for_iot/test/widget_test.dart index fc63705..8d6047a 100644 --- a/flutter_provisioning_for_iot/test/widget_test.dart +++ b/flutter_provisioning_for_iot/test/widget_test.dart @@ -6,6 +6,7 @@ // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; +import 'package:flutter_provisioning_for_iot/MainPage.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_provisioning_for_iot/main.dart'; @@ -13,7 +14,7 @@ import 'package:flutter_provisioning_for_iot/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(const MainPage()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);