• Ian Hickson's avatar
    License update (#45373) · 449f4a66
    Ian Hickson authored
    * Update project.pbxproj files to say Flutter rather than Chromium
    
    Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.
    
    * Update the copyright notice checker to require a standard notice on all files
    
    * Update copyrights on Dart files. (This was a mechanical commit.)
    
    * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.
    
    Some were already marked "The Flutter Authors", not clear why. Their
    dates have been normalized. Some were missing the blank line after the
    license. Some were randomly different in trivial ways for no apparent
    reason (e.g. missing the trailing period).
    
    * Clean up the copyrights in non-Dart files. (Manual edits.)
    
    Also, make sure templates don't have copyrights.
    
    * Fix some more ORGANIZATIONNAMEs
    Unverified
    449f4a66
main.dart 2.37 KB
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:mockito/mockito.dart';

void main() {
  final ThrowingHttpClient httpClient = ThrowingHttpClient();
  final HttpOverrides overrides = ProvidedHttpOverrides(httpClient);
  HttpOverrides.global = overrides;
  final ZoneSpecification specification = ZoneSpecification(
    handleUncaughtError:(Zone zone, ZoneDelegate delegate, Zone parent, Object error, StackTrace stackTrace) {
    FlutterError.reportError(FlutterErrorDetails(
      exception: error,
      context: ErrorDescription('In the Zone handleUncaughtError handler'),
      silent: false,
    ));
  });
  when(httpClient.getUrl(any)).thenAnswer((Invocation invocation) {
    final Completer<HttpClientRequest> completer = Completer<HttpClientRequest>.sync();
    completer.completeError(Error());
    return completer.future;
  });
  Zone.current.fork(specification: specification).run<void>(() {
    runApp(ImageLoader());
  });
}

class ImageLoader extends StatefulWidget {
  @override
  _ImageLoaderState createState() => _ImageLoaderState();
}

class _ImageLoaderState extends State<ImageLoader> {
  bool caughtError = false;

  @override
  void initState() {
    // This is not an image, but we don't care since we're using a faked
    // http client.
    const NetworkImage image = NetworkImage('https://github.com/flutter/flutter');
    final ImageStream stream = image.resolve(ImageConfiguration.empty);
    ImageStreamListener listener;
    listener = ImageStreamListener(
      (ImageInfo info, bool syncCall) {
        stream.removeListener(listener);
      },
      onError: (dynamic error, StackTrace stackTrace) {
        print('ERROR caught by framework');
        stream.removeListener(listener);
      },
    );
    stream.addListener(listener);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return const Text('hello', textDirection: TextDirection.ltr);
  }
}

class ThrowingHttpClient extends Mock implements HttpClient {}

class ProvidedHttpOverrides extends HttpOverrides {
  ProvidedHttpOverrides(this.httpClient);

  final ThrowingHttpClient httpClient;
  @override
  HttpClient createHttpClient(SecurityContext context) {
    return httpClient;
  }
}