flutter_mjpeg 2.0.4 flutter_mjpeg: ^2.0.4 copied to clipboard
Flutter widget to show mjpeg stream from URL, mainly used by ip camera, stop itself when not on screen
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_mjpeg/flutter_mjpeg.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends HookWidget {
@override
Widget build(BuildContext context) {
final isRunning = useState(true);
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Mjpeg(
isLive: isRunning.value,
error: (context, error, stack) {
print(error);
print(stack);
return Text(error.toString(), style: TextStyle(color: Colors.red));
},
stream:
'http://uk.jokkmokk.jp/photo/nr4/latest.jpg', //'http://192.168.1.37:8081',
),
),
),
Row(
children: <Widget>[
ElevatedButton(
onPressed: () {
isRunning.value = !isRunning.value;
},
child: Text('Toggle'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(),
)));
},
child: Text('Push new route'),
),
],
),
],
),
);
}
}