Adds flight,battery models and image file managment

This commit is contained in:
2025-07-04 23:39:34 +02:00
parent 72a8d25318
commit 3925421428
13 changed files with 485 additions and 36 deletions

View File

@ -1,10 +1,14 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:logging/logging.dart';
import 'package:rtime/db/db_helper.dart';
import 'package:rtime/images_manager.dart';
import 'package:rtime/models/drone.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart';
void main() {
if(Platform.isWindows || Platform.isLinux)
@ -74,7 +78,16 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
Future _incrementCounter() async {
DbHelper.instance.insertDrone(Drone
(
name: "Image test",
imageUuid: await ImagesManager.instance.createImage(ImageSource.camera)
));
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
@ -82,7 +95,6 @@ class _MyHomePageState extends State<MyHomePage> {
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
DbHelper.instance.insertDrone(Drone(name: "skibidi drone"));
});
}
@ -94,6 +106,43 @@ class _MyHomePageState extends State<MyHomePage> {
// 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.
var children =
<Widget>[
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
FutureBuilder(
future: Future<Widget>(() async
{
final drones = await DbHelper.instance.getDrones();
if(drones.isEmpty)
{
return Icon(Icons.question_mark);
}
final image = await ImagesManager.instance.loadImage(drones.first.imageUuid!);
if(image == null)
{
return Icon(Icons.error);
}
return image;
}),
builder: (BuildContext ctx, AsyncSnapshot<Widget> img)
{
if(!img.hasData)
{
return Center(child: CircularProgressIndicator(),);
}
return img.data!;
}
),
Icon(Icons.build)];
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
@ -122,14 +171,8 @@ class _MyHomePageState extends State<MyHomePage> {
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
children: children,
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
@ -139,3 +182,4 @@ class _MyHomePageState extends State<MyHomePage> {
);
}
}