Closed wasimakram3 closed 4 years ago
Can you provide more information? I'm not sure what you mean by widget child (I never use bootstrap).
Actually we are using bootstrap child widget to use in flutter web. I don't know how to call the void createPieChart() in the bootstrap child content widget. Also instead of createContainer function, how to merge container with that bootstrap child widget (Ex: col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 given in last one with text 'Line chart').
Given source code below:
import 'package:flutter/material.dart'; import 'package:flutter_bootstrap/flutter_bootstrap.dart'; import 'dart:html'; import 'package:modern_charts/modern_charts.dart' as modern; import 'package:http/http.dart' as http;
void main() => runApp(Application());
class Application extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Inventory', home: DemoPage(), ); } }
class DemoPage extends StatefulWidget { @override _DemoPageState createState() => _DemoPageState(); }
class _DemoPageState extends State
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Inventory', style: TextStyle(color: Colors.black)),
backgroundColor: Colors.white,
),
body: SingleChildScrollView(
child: BootstrapContainer(
fluid: true,
decoration: BoxDecoration(color: Colors.white),
children: [
BootstrapContainer(
fluid: true,
decoration: BoxDecoration(color: Colors.white),
padding: const EdgeInsets.only(top: 20),
children:
class ContentWidget extends StatelessWidget { const ContentWidget({ Key key, this.text, this.color, }) : super(key: key);
final String text; final Color color;
@override Widget build(BuildContext context) { return Container( height: 150, color: color, child: Text(text), alignment: Alignment.center, ); } }
void createPieChart() { var changeDataButton = ButtonElement()..text = 'Change data'; //document.body.append(changeDataButton);
var insertRemoveRowButton = ButtonElement()..text = 'Insert/remove data row'; //document.body.append(insertRemoveRowButton);
//var container = createContainer(); var container; var table = modern.DataTable([ ['Browser', 'Share'], ['Chrome', 35], ['Firefox', 20], ['IE', 30], ['Opera', 5], ['Safari', 8], ['Other', 2] ]); var chart = modern.PieChart(container); chart.draw(table, { 'animation': { 'onEnd': () { changeDataButton.disabled = false; insertRemoveRowButton.disabled = false; } }, 'pieHole': .5, 'series': { 'counterclockwise': true, 'labels': {'enabled': true}, 'startAngle': 90 + 10 * 360, }, 'title': {'text': 'Pie Chart Demo'}, });
void disableAllButtons() { changeDataButton.disabled = true; insertRemoveRowButton.disabled = true; }
changeDataButton.onClick.listen((_) { disableAllButtons(); for (var row in table.rows) { for (var i = 1; i < table.columns.length; i++) { // row[i] = rand(2, 25); } } chart.update(); });
var insertRow = true; insertRemoveRowButton.onClick.listen((_) { insertRemoveRowButton.disabled = true; if (insertRow) { var values = ['New', 6]; table.rows.insert(2, values); } else { table.rows.removeAt(2); } insertRow = !insertRow; chart.update(); }); }
I see. This package supports web only. To create charts in Flutter, you should use a package that supports it. Here are some good ones
For example . i'm using your piechart and need to add it in the bootstrap widget . I'm calling pieChart() in child bootstrap. it shows void error. How to add the container in it. can you give a sample code for adding charts and calling in widget child