title: Geting data from mysql to StreamBuilder Flutter
body: <p>I have an assignment and I have to take data from mysql server into a flutter and pass it to StreamBuilder and I was trying to use the same class we are using it in firebase and now I have problem with passing the data that I already take it from the server into the StreamBuilder and as I remember I have to use a different type of snapshot, any help.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Server',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.pink,
        ),
        home: MyHomePage(title: 'Flutter Server App'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    get documents =&gt; null;
  
  
  
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          centerTitle: true,
        ),
      );
    }
  
    Future getData() async{
      var url = 'https://milk-white-reveille.000webhostapp.com/get.php';
      http.Response response = await http.get(url);
      var data = jsonDecode(response.body);
      print(data.toString());
  
  
    }
  
    @override
    void initState() {
      getData();
    }
  }
  
  class BookList extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new StreamBuilder(
        stream: _MyHomePageState.getData().snapshot(),
        builder: (BuildContext context, AsyncSnapshot&lt;_MyHomePageState&gt; snapshot) {
          if (snapshot.hasData) return new Text('Loading...');
          return new ListView(
            children: snapshot.data.documents.map((document) {
              return new ListTile(
                title: new Text(document['title']),
                subtitle: new Text(document['type']),
              );
            }).toList(),
          );
        },
  
      );
  
    }
  
  }
  </code></pre>
  
  <p>The new code is this </p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  import 'dart:async';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Server',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.pink,
        ),
        home: MyHomePage(title: 'Flutter Server App'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    StreamController _streamController = StreamController();
    Timer _timer;
    var data;
  
    Future getData() async {
      var url = 'https://milk-white-reveille.000webhostapp.com/get.php';
      http.Response response = await http.get(url);
  
  
      String jsonsDataString = response.body.toString(); // toString of Response's body is assigned to jsonDataString
      data = jsonDecode(jsonsDataString);
      print(data.toString());
      //Add your data to stream
      _streamController.add(data);
    }
  
    @override
    void initState() {
      getData();
  
      //Check the server every 5 seconds
      _timer = Timer.periodic(Duration(seconds: 5), (timer) =&gt; getData());
  
      super.initState();
    }
  
    @override
    void dispose() {
      //cancel the timer
      if (_timer.isActive) _timer.cancel();
  
      super.dispose();
    }
    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(
          title: new Text("Home"),
        ),
        body: new _MySql()
  
            );
  
    }
  }
  
  
  
  class _MySql extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: StreamBuilder(
          stream: _MyHomePageState()._streamController.stream,
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData)
              return ListView(
                children: snapshot.data((data) {
                  return ListTile(
                    title: Text(data['title']),
                    subtitle: Text(data['type']),
                  );
                }).toList(),
              );
            return CircularProgressIndicator();
          },
        ),
      );
    }
  }
  </code></pre>
  
  <p>but on the phone screen loading... appearing 
  this one from terminal <code>
  E/flutter (10194): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FormatException: Unexpected character (at character 1)
  E/flutter (10194): connected{"title":"maen","type":"dev"}</code> </p>