I mounted a trial code using a ListView widget to show three cards: Result(), ImputField(callbackFunction: callback) and VideoStreamer() item.
Is it possible that the callbackFunction only rebuilds the Result() widget, so that a running video is not reloaded every time a new value is submitted form the InputFiled?
Thanks Martin
import 'package:flutter/material.dart';
import 'package:mustoappmodel/reusable.dart';
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
String value = '';
class _HomeState extends State<Home> {
void callback(String result) {
value = result;
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('test module')),
body: ListView(
children: [
Result(), // Shows whats is put in InputField
ImputField(callbackFunction: callback),
VideoStreamer(), // a steram should not be interrupted
],
),
);
}
}
import 'package:flutter/material.dart';
import '../homepage.dart';
class Result extends StatefulWidget {
const Result({super.key});
@override
State<Result> createState() => _ResultState();
}
class _ResultState extends State<Result> {
@override
Widget build(BuildContext context) {
return Container(
height: 150,
margin: const EdgeInsets.all(10),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(children: [Text(value, textAlign: TextAlign.center)]),
),
);
}
}
class ImputField extends StatelessWidget {
ImputField({super.key, required this.callbackFunction});
final Function callbackFunction;
final TextEditingController _txtController = TextEditingController();
@override
Widget build(BuildContext context) {
return Container(
height: 150,
margin: const EdgeInsets.all(10),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
controller: _txtController,
onSubmitted: (value) {
print('here: $value');
callbackFunction(value);
_txtController.clear();
},
),
),
);
}
}
class VideoStreamer extends StatefulWidget {
const VideoStreamer({super.key});
@override
State<VideoStreamer> createState() => _VideoStreamerState();
}
class _VideoStreamerState extends State<VideoStreamer> {
@override
Widget build(BuildContext context) {
return Container(
height: 150,
margin: const EdgeInsets.all(10),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: const BorderRadius.all(Radius.circular(20)),
),
);
}
}