"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/packages/flutter/lib/src/widgets/orientation_builder.dart" (13 Nov 2020, 2294 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 // @dart = 2.8
    6 
    7 import 'basic.dart';
    8 import 'framework.dart';
    9 import 'layout_builder.dart';
   10 import 'media_query.dart';
   11 
   12 /// Signature for a function that builds a widget given an [Orientation].
   13 ///
   14 /// Used by [OrientationBuilder.builder].
   15 typedef OrientationWidgetBuilder = Widget Function(BuildContext context, Orientation orientation);
   16 
   17 /// Builds a widget tree that can depend on the parent widget's orientation
   18 /// (distinct from the device orientation).
   19 ///
   20 /// See also:
   21 ///
   22 ///  * [LayoutBuilder], which exposes the complete constraints, not just the
   23 ///    orientation.
   24 ///  * [CustomSingleChildLayout], which positions its child during layout.
   25 ///  * [CustomMultiChildLayout], with which you can define the precise layout
   26 ///    of a list of children during the layout phase.
   27 ///  * [MediaQueryData.orientation], which exposes whether the device is in
   28 ///    landscape or portrait mode.
   29 class OrientationBuilder extends StatelessWidget {
   30   /// Creates an orientation builder.
   31   ///
   32   /// The [builder] argument must not be null.
   33   const OrientationBuilder({
   34     Key key,
   35     @required this.builder,
   36   }) : assert(builder != null),
   37        super(key: key);
   38 
   39   /// Builds the widgets below this widget given this widget's orientation.
   40   ///
   41   /// A widget's orientation is simply a factor of its width relative to its
   42   /// height. For example, a [Column] widget will have a landscape orientation
   43   /// if its width exceeds its height, even though it displays its children in
   44   /// a vertical array.
   45   final OrientationWidgetBuilder builder;
   46 
   47   Widget _buildWithConstraints(BuildContext context, BoxConstraints constraints) {
   48     // If the constraints are fully unbounded (i.e., maxWidth and maxHeight are
   49     // both infinite), we prefer Orientation.portrait because its more common to
   50     // scroll vertically then horizontally.
   51     final Orientation orientation = constraints.maxWidth > constraints.maxHeight ? Orientation.landscape : Orientation.portrait;
   52     return builder(context, orientation);
   53   }
   54 
   55   @override
   56   Widget build(BuildContext context) {
   57     return LayoutBuilder(builder: _buildWithConstraints);
   58   }
   59 }