I have a flutter quiz project with a radio widget and when the next button is pressed the data will change (change questions) I try to use WebView on the question or question text but there is no data change,
The following is a quiz with text
Container(
width: 250,
child: new Text(
"${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}",
maxLines: 2,
overflow: TextOverflow.ellipsis,),)
and that I do with the WebView
new Container(
height: 50,
width: 250,
child: WebView(
initialUrl: '${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);},
)),
First create a Controller for your WebView
WebViewController _webViewController = WebViewController();
then assign it to webview
new Container(
height: 50,
width: 250,
child: WebView(
controller: _webViewController,
initialUrl: '${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);},
)),
In your nextButton press callback(where you are increasing _counter and loop variables) load next through _webViewController
_webViewController.loadUrl('${dataQuestions["list_question"][_counter]["data_option"][loop]["option_text"]}');
Related
I am using react-youtube package and I have set the options to remove most of the youtube's branding and controls:
const options = {
height: 'auto',
width: '100%',
playerVars: {
// https://developers.google.com/youtube/player_parameters
controls: 0,
enablejsapi: 1,
modestbranding: 1,
showinfo: 0
}
} as const
<YouTube videoId="xyQ5qD-u-J7" opts={options} ref={videoElement}/>
But, the youtube frame is still showing all the options just as if it were displayed on the youtube channel. Why is the branding not removed?
i'm using sqflite package and i want to read a data from it ,the data ins in a table namedmy_tablein the table i want to read name property on it and use it in a widget like text widget here is what i've tried \
list = await db.query('my_table', 'name');
#override
Widget build(BuildContext context) {
ScrollController _scrollController = new ScrollController();
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
},
),
body: Container(
color: Colors.blue,
height: 1000,
width: MediaQuery.of(context).size.width,
child: Text('${list}'),
), );
}
Please provide more information!
When you are using SQFLite:
Reading:
https://github.com/tekartik/sqflite/blob/master/sqflite/doc/sql.md
query is for reading a table content. It returns a list of map.
var list = await db.query('my_table', columns: ['name', 'type']);
I can recommend this guide for SQFLite
As titled. I have my nodeSvgShape defined as:
const nodeShape = {
shape: 'image',
shapeProps: {
width: 40,
height: 40,
x: -20,
y: -20,
href:{tree_node},
}
}
I made sure to import {tree_node} from the correct directory (changing that to a wrong directory makes React give a compilation error). However, the nodes look like the default image that would show up if the image failed to load.
I tried replacing that href with an online link (but different image) and it works:
const nodeShape = {
shape: 'image',
shapeProps: {
width: 40,
height: 40,
x: -20,
y: -20,
href:"https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png",
}
}
But again, that's not the image I actually want, therefore I still need to figure out why my local image failed to load. What could be the reason? Thanks
I have a layout like the attached image. Im looking to have in the same screen and horizontal Listview with the popular/latest items and below a GridView with the full list of items.
The ListView should have horizontal scrolling, but also, all the screen can vertical scroll. The dark bar at the right simulates the scrollbar (not necesary, just for illustration purposes).
You can see this behavior in the Google Play app itself, where you can swipe horizontal to see more items in a category, but also scroll vertical to see more category lists.
Im tried Stack and Column widgets, but nothing works. Any idea in how to structure this layout?
You can use Slivers , try this example I made :
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(),
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: SizedBox(
height: 100,
child: ListView.builder(
itemExtent: 150,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => Container(
margin: EdgeInsets.all(5.0),
color: Colors.orangeAccent,
),
itemCount: 20),
),
),
SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1.5,
),
delegate: SliverChildBuilderDelegate(
(context, index) => Container(
margin: EdgeInsets.all(5.0),
color: Colors.yellow,
),
),
)
],
));
}
Also you can learn more about Sliver from this link : https://medium.com/flutter-io/slivers-demystified-6ff68ab0296f
I'm trying to get familiar with flutter and I'm facing some weird case. I want to build a dynamic ListView where a + button allows to add elements. I wrote the following State code:
class MyWidgetListState extends State<MyWidgetList> {
List<Widget> _objectList = <Widget>[
new Text('test'),
new Text('test')
];
void _addOne() {
setState(() {
_objectList.add(new Text('test'));
});
}
void _removeOne() {
setState(() {
_objectList.removeLast();
});
}
#override
Widget build(BuildContext context) {
return new Column(
children: <Widget>[
new ListView(
shrinkWrap: true,
children: _objectList
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new IconButton(
icon: new Icon(Icons.remove_circle),
iconSize: 36.0,
tooltip: 'Remove',
onPressed: _objectList.length > 2 ? _removeOne : null,
),
new IconButton(
icon: new Icon(Icons.add_circle),
iconSize: 36.0,
tooltip: 'Add',
onPressed: _addOne,
)
],
),
new Text(_objectList.length.toString())
],
);
}
}
My problem here is that the ListView is visually stuck with the 2 elements I initialized it with.
Internally the _objectList is well managed. For testing purpose I added a simple Text widget at the bottom that shows the size of the list. This one works fine when I click the Add/Remove buttons and it gets properly refreshed. Am I missing something?
Flutter is based around immutable data. Meaning that if the reference to an object didn't change, the content didn't either.
The problem is, in your case you always send to ListView the same array, and instead mutate its content. But this leads to ListView assuming the list didn't change and therefore prevent useless render.
You can change your setState to keep that in mind :
setState(() {
_objectList = List.from(_objectList)
..add(Text("foo"));
});
Another Solution!!
Replace ListView with ListView.builder
Code:
ListView.builder(
itemBuilder: (ctx, item) {
return _objectList[item];
},
shrinkWrap: true,
itemCount: _objectList.length,
),
Output: