title: initialize global key with widget without attach it to screen
body: <p>I'm trying to initialize global key with stateless or stateful widget but without attaching this widget to screen.</p>
  
  <p>i tried this:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/rendering.dart';
  import 'package:flutter/services.dart' show rootBundle;
  import 'dart:ui' as ui show ImageFilter, Gradient, Image;
  
  void main() {
     runApp(MyApp());
  }
  
  class MyApp extends StatefulWidget{
    @override
    State&lt;StatefulWidget&gt; createState() {
      // TODO: implement createState
      return MyAppState();
    }
  
  }
  class MyAppState extends State&lt;MyApp&gt;{
    @override
    void initState()async {
      var image = await getMarkerIcon(context);
      super.initState();
    }
    @override
    Widget build(BuildContext context) {
       return Material(
        child: Container(),
      );
    }
  }
  Future&lt;ui.Image&gt; getMarkerIcon(BuildContext context) async {
    final key = new GlobalKey();
    MarkerText widget = MarkerText(
      key: key,
    );
    widget.build(context);
  
    RenderRepaintBoundary boundary = key.currentContext.findRenderObject();
    ui.Image image = await boundary.toImage();
    return image;
  
    return image;
  }
  
  class MarkerText extends StatelessWidget {
    MarkerText({Key key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return Text('example');
    }
  }
  </code></pre>
  
  <p>after this, I get globalKey with null currentContext and null currentState. 
  any idea to do this task? 
  and any explanation when exactly globalkey initialize?
  thanks in advance</p>
  
  <p>update : 
  after one day search I found this 2 solutions in this link:
  <a href="https://stackoverflow.com/questions/57408315/build-the-widget-off-screen">Build the widget off screen</a></p>