charting-library-examples icon indicating copy to clipboard operation
charting-library-examples copied to clipboard

Flutter sample

Open zhangyu0218 opened this issue 5 years ago • 33 comments

Is there an tradingview example of flutter?

zhangyu0218 avatar Jan 30 '19 07:01 zhangyu0218

No, we don't have such example

kirchet avatar Jan 30 '19 20:01 kirchet

Feel free to make a PR with such example!

timocov avatar Feb 01 '19 12:02 timocov

can you support flutter? flutter is fashion

buckcao avatar Sep 12 '19 09:09 buckcao

Hello, we will work on it using Flutter, have you finally worked on it?

Pascaltallarida avatar Oct 03 '19 17:10 Pascaltallarida

have you finally worked on it?

No.

timocov avatar Oct 15 '19 17:10 timocov

hi can u do it in flutter?

TinkerBuild avatar May 06 '20 02:05 TinkerBuild

Unfortunately, current state of WebView in Flutter is not acceptable. The widget still needs a lot of improvements. At the moment you can use combination of native code and Flutter. Check this link out

makedonsky94 avatar May 06 '20 09:05 makedonsky94

Hey, anybody has any news regarding this ?

alinetskyi avatar Sep 30 '20 18:09 alinetskyi

Is there a tradingview example of flutter?

muzairk92 avatar Feb 24 '21 17:02 muzairk92

https://pub.dev/packages/trading_chart

Is this worthwhile looking into ?

kkapuria3 avatar Apr 10 '21 05:04 kkapuria3

Since Flutter 2.0, web channel is now out of beta. I would also be very interested in Flutter example with Tradingview.

teneon avatar Apr 14 '21 00:04 teneon

I agree, please support Flutter, Flutter is growing super fast.

ducthong97 avatar Jul 31 '21 12:07 ducthong97

Hi guys! Sorry for restarting this thread but I managed to run tv charting_library using flutter_inappwebview and follow this sample. It is running default and basic sample tv charting library.

import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; class TradindView extends StatefulWidget { @override _TradindViewState createState() => _TradindViewState(); } final InAppLocalhostServer localhostServer = new InAppLocalhostServer(); class _TradindViewState extends State<TradindView> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('InAppLocalhostServer Example'), ), body: Container( child: Column(children: <Widget>[ Expanded( child: InAppWebView( initialUrlRequest: URLRequest( url: Uri.parse("http://localhost:8080/assets/index.html")), onWebViewCreated: (controller) {}, onLoadStart: (controller, url) {}, onLoadStop: (controller, url) {}, ), ) ])), ); } }

my pubspec.yalm:

assets: - assets/index.html - assets/charting_library/ - assets/datafeeds/ - assets/charting_library/bundles/ - assets/datafeeds/udf/dist/bundle.js - assets/datafeeds/udf/dist/polyfills.js

thicow avatar Sep 07 '21 01:09 thicow

@thicow could you please go into more detail about this? I'm trying to implement something similar

alexanderytaylor avatar Nov 07 '21 07:11 alexanderytaylor

@thicow could you please go into more detail about this? I'm trying to implement something similar

Hi @alexanderytaylor ! I implemented exactly it. Using flutter_inappwebview I created a widget with InAppWebView using initialUrlRequest: URLRequest(url: Uri.parse("http://localhost:8080/assets/index.html")),

I download tv-chart-library into assets folder and configure pubspec.yalm:

assets:

  • assets/index.html
  • assets/charting_library/
  • assets/datafeeds/
  • assets/charting_library/bundles/
  • assets/datafeeds/udf/dist/bundle.js
  • assets/datafeeds/udf/dist/polyfills.js

and it works fine! Inside my index.html I configured the datasource to render the chart.

thicow avatar Nov 07 '21 19:11 thicow

@thicow thanks for the reply! Does setting the initialUrlRequest to localhost work when the site is live as well or just for debugging?

alexanderytaylor avatar Nov 07 '21 22:11 alexanderytaylor

@thicow thanks for the reply! Does setting the initialUrlRequest to localhost work when the site is live as well or just for debugging?

Localhost everytime! Localhost because index.html works like a angular app (SPA)... I don't need open a remote website in initialUrlRequest. But the most important is setting the urldatafeed to production datafeed in file index.html (https://github.com/tradingview/charting_library/blob/master/index.html) on line

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),

thicow avatar Nov 08 '21 01:11 thicow

Hi @timocov, @kirchet , is there any update on this issue? Any PoC, sample projects, dummy code etc. that your team can provide will be much appreciated. Please update.

VishalS01 avatar Jan 05 '22 10:01 VishalS01

Localhost everytime! Localhost because index.html works like a angular app (SPA)... I don't need open a remote website in initialUrlRequest. But the most important is setting the urldatafeed to production datafeed in file index.html (https://github.com/tradingview/charting_library/blob/master/index.html) on line

datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo-feed-data.tradingview.com"),

Hi @thicow ! If possible, could you provide an example project or an example of what is in the following files

  • assets/index.html
  • assets/datafeeds/
  • assets/charting_library/bundles/
  • assets/datafeeds/udf/dist/bundle.js
  • assets/datafeeds/udf/dist/polyfills.js

serzhikdnepr avatar Jan 18 '22 17:01 serzhikdnepr

@serzhikdnepr see https://github.com/tradingview/charting_library/, all files are there

timocov avatar Jan 18 '22 17:01 timocov

@serzhikdnepr see https://github.com/tradingview/charting_library/, all files are there

@thicow Thanks for the answer! I don't have access to this repository

serzhikdnepr avatar Jan 18 '22 17:01 serzhikdnepr

Hi guys is there any update?

coditori avatar Feb 05 '22 13:02 coditori

if need works with flutter_inappwebview .

  1. add flutter_inappwebview: ^5.3.2
  2. Create index.hstm and td.js files in assets folder. And define its, under to assets index.html
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
    <title>Document</title>
</head>
<body>
<div class="tradingview-widget-container">
    <div id="tradingview_17f8f"></div>
    <div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-AAPL/" rel="noopener" target="_blank"><span class="blue-text">AAPL Chart</span></a> by TradingView</div>
</div>

<script type="text/javascript" src="./td.js"></script>
</body>
</html>

td.js

  new TradingView.widget(
  {
  "width": 350,
  "height": 480,
  "symbol": "NASDAQ:AAPL",
  "interval": "D",
  "timezone": "Etc/UTC",
  "theme": "dark",
  "style": "1",
  "locale": "en",
  "toolbar_bg": "#f1f3f6",
  "enable_publishing": false,
  "allow_symbol_change": false,
  "container_id": "tradingview_17f8f"
}
  );

3 main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await localhostServer.start();
  if (Platform.isAndroid) {
    await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
    var swAvailable = await AndroidWebViewFeature.isFeatureSupported(
        AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE);
    var swInterceptAvailable = await AndroidWebViewFeature.isFeatureSupported(
        AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST);
    if (swAvailable && swInterceptAvailable) {
      AndroidServiceWorkerController serviceWorkerController =
          AndroidServiceWorkerController.instance();

      serviceWorkerController.serviceWorkerClient = AndroidServiceWorkerClient(
        shouldInterceptRequest: (request) async {
          print(request);
          return null;
        },
      );
    }
  }
runApp(const Forex());
}
```
4. 
```
class MYView extends StatefulWidget {
  const MYView ({Key? key}) : super(key: key);

  @override
  State<MYView > createState() => _MyViewState();
}

class _MyViewState extends State<MYView > {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          width: Get.width,
          height: Get.height,
          child: InAppWebView(
            initialUrlRequest: URLRequest(
                url: Uri.parse("http://localhost:8080/assets/web/index.html")),
            androidOnPermissionRequest: (controller, origin, resources) async {
              return PermissionRequestResponse(
                  resources: resources,
                  action: PermissionRequestResponseAction.GRANT);
            },
            onWebViewCreated: (controller) {},
            onLoadStart: (controller, url) {},
            onLoadStop: (controller, url) {},
          ),
        ),
      ),
    );
  }
}
```
and works

caglarylmz avatar Mar 18 '22 12:03 caglarylmz

await localhostServer.start();

could not resolve reference

segungreat avatar Apr 17 '22 19:04 segungreat

await localhostServer.start();

could not resolve reference

Solved, Thanks

segungreat avatar Apr 18 '22 21:04 segungreat

i'm trying to add some data to TradingView chart. but i's not working,

` late InAppWebViewController _webViewController;

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('TradingView Chart'), ), body: InAppWebView( initialUrlRequest: URLRequest( url: Uri.parse('http://localhost:8080/assets/web/index.html'), ), onWebViewCreated: (InAppWebViewController controller) { _webViewController = controller; }, onLoadStop: (controller, url) async { // Wait for the TradingView widget to load await Future.delayed(Duration(seconds: 2));

      // Check if the TradingView widget is displayed correctly
      bool isWidgetDisplayed =
          await _webViewController.evaluateJavascript(source: '''
        // Check if the TradingView widget is displayed
        var widgetContainer = document.querySelector('.tradingview-widget-container');
        var isWidgetDisplayed = widgetContainer && widgetContainer.offsetWidth > 0 && widgetContainer.offsetHeight > 0;
        isWidgetDisplayed;
      ''');

      if (isWidgetDisplayed) {
        print('TradingView widget loaded successfully');
        _loadTradingViewChart();
      } else {
        print('Error: TradingView widget did not load');
      }
    },
  ),
);

}`

    void _loadTradingViewChart() {
    List<Map<String, dynamic>> data = [
      {
        "time": 1648041600000,
        "open": 58353.11,
        "high": 58727.53,
        "low": 56566.16,
        "close": 56954.84
      },
      {
        "time": 1647955200000,
        "open": 58154.92,
        "high": 59129.91,
        "low": 57601.37,
        "close": 58353.11
      },
      {
        "time": 1647868800000,
        "open": 56032.22,
        "high": 58713.57,
        "low": 55253.87,
        "close": 58154.92
      },
      {
        "time": 1647782400000,
        "open": 57517.58,
        "high": 57569.16,
        "low": 54754.38,
        "close": 56032.22
      },
      {
        "time": 1647696000000,
        "open": 56853.84,
        "high": 58082.69,
        "low": 55822.07,
        "close": 57517.58
      },
    ];

    String jsonData = jsonEncode(data);

    String js = '''
    new TradingView.widget({
      "width": 350,
      "height": 480,
      "symbol": "BTC/USDT",
      "interval": "D",
      "timezone": "Etc/UTC",
      "theme": "light",
      "style": "2",
      "locale": "en",
      "toolbar_bg": "#f1f3f6",
      "enable_publishing": false,
      "allow_symbol_change": false,
      "datafeed": {
        "data": ${jsonData},
        "datafeed": new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com")
      },
      "container_id": "tradingview_17f8f",
      "overrides": {
        "mainSeriesProperties.style": 1,
        "paneProperties.background": "#ffffff",
        "paneProperties.vertGridProperties.color": "#e1e1e1",
        "paneProperties.horzGridProperties.color": "#e1e1e1",
        "symbolWatermarkProperties.transparency": 90,
        "scalesProperties.textColor" : "#AAA",
        "scalesProperties.backgroundColor" : "#FFF",
        "scalesProperties.lineColor" : "#D4D4D4",
        "scalesProperties.priceLabelsColor" : "#787B86"
      },
      "studies_overrides" : {
        "volume.volume.color.0" : "#6fba44",
        "volume.volume.color.1" : "#f25866",
        "volume.volume.transparency" : 70,
        "volume.show ma" : false,
        "bollinger bands.median.color" : "#33FF88",
        "bollinger bands.upper.linewidth" : 7
      },
      "loading_screen": { 
        "backgroundColor": "#FFFFFF", 
        "foregroundColor": "#000000"
      }
    });
  ''';

    _webViewController.evaluateJavascript(source: js).whenComplete(() {
      print("Complete");
    }).onError((error, stackTrace) {
      print("print $e");
    });
  }
}

this is working without this,

      "datafeed": {
        "data": ${jsonData},
        "datafeed": new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com")
      },

but i need to add my data list to chart @caglarylmz Plz Help me

DasunInduwara avatar Mar 24 '23 11:03 DasunInduwara

Any update on flutter support?

tapas-tw avatar Mar 27 '23 10:03 tapas-tw

any update here?

doanngoctu95 avatar Apr 06 '23 07:04 doanngoctu95

Any Update?

Floul avatar Jun 15 '23 14:06 Floul

Any update?

ghost avatar Jul 04 '23 08:07 ghost