Skip to content

Commit

Permalink
refactoring to a widget dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasoskorep committed Jun 23, 2022
1 parent 9ec737d commit 8044485
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# tensordex_mobile

Pokedex made using Tensorflow 2.0
Pokedex made using Tensorflow 2.9 and flutter 3.0.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

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.
Build instructions:
* coming when I have time
* for now just install_tflite.script and then flutter build this thing
*
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:tensordex_mobile/ui/tensordex_home.dart';
import 'package:tensordex_mobile/widgets/tensordex_home.dart';
import 'package:tensordex_mobile/utils/logger.dart';

Future<void> main() async {
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/poke_view.dart → lib/widgets/poke_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import '../utils/logger.dart';
import '../tflite/data/recognition.dart';
import '../tflite/data/stats.dart';

/// [PokedexView] sends each frame for inference
class PokedexView extends StatefulWidget {
/// [PokeFinder] sends each frame for inference
class PokeFinder extends StatefulWidget {
/// Callback to pass results after inference to [HomeView]
final Function(List<Recognition> recognitions) resultsCallback;

/// Callback to inference stats to [HomeView]
final Function(Stats stats) statsCallback;

/// Constructor
const PokedexView(
const PokeFinder(
{Key? key, required this.resultsCallback, required this.statsCallback})
: super(key: key);

@override
State<PokedexView> createState() => _PokedexViewState();
State<PokeFinder> createState() => _PokeFinderState();
}

class _PokedexViewState extends State<PokedexView> with WidgetsBindingObserver {
class _PokeFinderState extends State<PokeFinder> with WidgetsBindingObserver {
late List<CameraDescription> cameras;
late CameraController cameraController;
late MLIsolate _mlIsolate;
Expand Down
12 changes: 6 additions & 6 deletions lib/ui/results_view.dart → lib/widgets/results.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import 'package:flutter/material.dart';
import 'package:tensordex_mobile/ui/poke_view.dart';
import 'package:tensordex_mobile/widgets/poke_finder.dart';
import 'package:tensordex_mobile/tflite/data/recognition.dart';
import 'package:tensordex_mobile/tflite/data/stats.dart';


/// [PokedexView] sends each frame for inference
class ResultsView extends StatefulWidget {
/// [PokeFinder] sends each frame for inference
class Results extends StatefulWidget {
final List<Recognition> recognitions;
final Stats stats;
/// Constructor
const ResultsView(this.recognitions, this.stats, {Key? key}) : super(key: key);
const Results(this.recognitions, this.stats, {Key? key}) : super(key: key);

@override
State<ResultsView> createState() => _ResultsViewState();
State<Results> createState() => _ResultsState();
}

class _ResultsViewState extends State<ResultsView> {
class _ResultsState extends State<Results> {
@override
void initState() {
super.initState();
Expand Down
12 changes: 6 additions & 6 deletions lib/ui/tensordex_home.dart → lib/widgets/tensordex_home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:tensordex_mobile/ui/poke_view.dart';
import 'package:tensordex_mobile/ui/results_view.dart';
import 'package:tensordex_mobile/widgets/poke_finder.dart';
import 'package:tensordex_mobile/widgets/results.dart';

import '../utils/logger.dart';
import '../tflite/data/recognition.dart';
Expand Down Expand Up @@ -44,14 +44,14 @@ class _TensordexHomeState extends State<TensordexHome> {
super.dispose();
}

/// Callback to get inference results from [PokedexView]
/// Callback to get inference results from [PokeFinder]
void resultsCallback(List<Recognition> results) {
setState(() {
this.results = results;
});
}

/// Callback to get inference stats from [PokedexView]
/// Callback to get inference stats from [PokeFinder]
void statsCallback(Stats stats) {
setState(() {
this.stats = stats;
Expand All @@ -68,10 +68,10 @@ class _TensordexHomeState extends State<TensordexHome> {
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
PokedexView(
PokeFinder(
resultsCallback: resultsCallback,
statsCallback: statsCallback),
ResultsView(results, stats),
Results(results, stats),
],
),
),
Expand Down

0 comments on commit 8044485

Please sign in to comment.