Skip to content

Commit

Permalink
modification on README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wireMuffin committed Sep 23, 2019
1 parent 056faa4 commit e24f24e
Showing 1 changed file with 5 additions and 255 deletions.
260 changes: 5 additions & 255 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,259 +158,11 @@ Now you have every precautions settled.

All code in Flutter should be placed in `[$ProjectName]/lib`, we have a total of 2 .dart file:

#### `main.dart`

This is the main program of the whole project.

```dart
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image/image.dart' as im;
import 'videoRoute.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
//This is the entrance of the whole program
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Object Detection App',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Object Detection App'),
debugShowCheckedModeBanner: false,
//Do not show the debug banner in the top right corner of the App
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _textAppState = "You have not yet seleted any image";
bool isSwitched = true;
var _image = Image.network('http://172.20.10.6/capture?_cb=1554370194299');
String path (bool isSwi){
if(isSwi)
return "assets/bunny.mp4";
return "assets/bunnyShort.mp4";
}
//this is called when determining which video should be played when videoRoute is created.
void _changeTextState() {
setState(() {
_textAppState = "You have not yet seleted any image";
});
}
//this is called when we need to update the text field on top of the App.
void _cameraSelection() async{
imageCache.clear();
setState(() {
_image = Image.network('http://172.20.10.6/capture?_cb=1554370194299');
});
print("here!");
}
//this is called when getting an image from a web server, i.e ESP32's http server.
void _gallerySelection() async{
final imageFile = await ImagePicker.pickImage(
source: ImageSource.gallery,
maxWidth: 100.0,
maxHeight: 100.0);
//restrict the size of the image, because decoding binary image file using Flutter in iOS device is very slow.
im.Image image = im.decodeImage(imageFile.readAsBytesSync());
int pixelInfo = image.getPixel(image.width~/2, image.height~/2);
int red = pixelInfo & 0xff;
int blue = (pixelInfo>>16) & 0xff;
int green = (pixelInfo>>8) & 0xff;
setState(() {
_textAppState = "It is in rgb(" + red.toString() + ", " + green.toString() + ", " + blue.toString() + ") (gallery).";
});
}
//this is called when selecting an image from the built-in library.
void _tempCameraSelection() async{
final imageFile = await ImagePicker.pickImage(
source: ImageSource.camera,
maxWidth: 100.0,
maxHeight: 100.0
);
im.Image image = im.decodeImage(imageFile.readAsBytesSync());
int pixelInfo = image.getPixel(image.width~/2, image.height~/2);
int red = pixelInfo & 0xff;
int blue = (pixelInfo>>16) & 0xff;
int green = (pixelInfo>>8) & 0xff;
setState(() {
_textAppState = "It is in rgb(" + red.toString() + ", " + green.toString() + ", " + blue.toString() + ") (camera).";
});
}
//this is called when capturing an image using the device's own camera.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
//appBar is the top bar of the App
body: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_image,
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'$_textAppState',
),
FlatButton(
child: Icon(Icons.camera_alt),
textColor: Colors.grey,
onPressed: _cameraSelection,
),
FlatButton(
child: Icon(Icons.photo_album),
textColor: Colors.blue,
onPressed: _gallerySelection,
),
FlatButton(
child: Icon(Icons.camera_alt),
textColor: Colors.blue,
onPressed: _tempCameraSelection,
),
FlatButton(
child: Icon(Icons.video_library),
textColor: Colors.blue,
onPressed: () {
Navigator.push( context,
new MaterialPageRoute(builder: (context) {
return new VideoRoute(path: path(isSwitched));//VideoRoute() is in videoRoute.dart
}));
},
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Short"),
Switch(
value: isSwitched,
onChanged: (value) {
setState(() {
isSwitched = value;
});
},
activeTrackColor: Colors.lightBlueAccent,
activeColor: Colors.blue,
),
Text("Long"),
],
),
]
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _changeTextState,
child: Text("Clear"),
),
);
}
}
```

Modify the default `main.dart` file as above.

#### `videoRoute.dart`

This is a route for playing video.

```dart
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
class VideoRoute extends StatefulWidget {
final String path;
VideoRoute({Key key, this.path}) : super(key: key);
@override
_VideoRouteState createState() => _VideoRouteState();
}
class _VideoRouteState extends State<VideoRoute> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset(
widget.path)
..addListener((){
if(!_controller.value.isPlaying){
Navigator.pop(context);
}
})
/*
this listener listen for the playing status of the video
i.e when the video is not playing(the video is ended or paused(not provided in this route))
this route will be pop out of the route stack, i.e. return to the main route.
*/
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
_controller.play();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back_ios),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
```

Create the above `videoRoute.dart` file in `[$ProjectName]/lib`:
`main.dart`

`videoRoute.dart`

#### How to Create New File (Creating VideoRoute.dart)

Right click on the structure area's `lib` folder, choose New->Dart File.

Expand All @@ -420,8 +172,6 @@ Right click on the structure area's `lib` folder, choose New->Dart File.

![5.videoRouteNaming](https://tva1.sinaimg.cn/large/006y8mN6gy1g79j8y486ij30o60c4wh7.jpg)

Modify this `videoRoute.dart` as above.



All things are settled, you can now debug this program with your device(s).
Expand Down

0 comments on commit e24f24e

Please sign in to comment.