Flutter some tips

1. Obtain the status bar height

import 'dart:ui';
MediaQueryData.fromWindow(window).padding.top

2. Set the height of AppBar

Scaffold( 
        appBar: PreferredSize(
        child: AppBar(
        ),
        preferredSize: Size.fromHeight(screenSize.height * 0.07))
);

3. The system default AppBar, TabBar height

inDart Packages/flutter/src/material/constans.dart

/// The height of the toolbar component of the [AppBar].
const double kToolbarHeight = 56.0;

/// The height of the bottom navigation bar.
const double kBottomNavigationBarHeight = 56.0;

/// The height of a tab bar containing text.
const double kTextTabBarHeight = 48.0;

/// The amount of time theme change animations should last.
const Duration kThemeChangeDuration = Duration(milliseconds: 200);

/// The radius of a circular material ink response in logical pixels.
const double kRadialReactionRadius = 20.0;

/// The amount of time a circular material ink response should take to expand to its full size.
const Duration kRadialReactionDuration = Duration(milliseconds: 100);

/// The value of the alpha channel to use when drawing a circular material ink response.
const int kRadialReactionAlpha = 0x1F;

/// The duration of the horizontal scroll animation that occurs when a tab is tapped.
const Duration kTabScrollDuration = Duration(milliseconds: 300);

/// The horizontal padding included by [Tab]s.
const EdgeInsets kTabLabelPadding = EdgeInsets.symmetric(horizontal: 16.0);

/// The padding added around material list items.
const EdgeInsets kMaterialListPadding = EdgeInsets.symmetric(vertical: 8.0);

4. Get the current timestamp

var now = new new DateTime.Now (); 
Print (now.millisecondsSinceEpoch); // milliseconds, the time stamp 13 

/ * * or * / 
/ * * Returns the current timestamp * / 
  static  int with currentTimeMillis () {
     return  new new the DateTime . .now () millisecondsSinceEpoch; 
  }

The time stamp is converted into date

var now = new DateTime.now ();
var a = now.millisecondsSinceEpoch;  // 时间戳 
print (DateTime.fromMillisecondsSinceEpoch (a));

6. acquiring control size and position relative to the screen

1 . First, first need to control rendering 
initialization GlobalKey: GlobalKey anchorKey = GlobalKey (); 

2 addition of the key in the following to be measured control:. 
Child: the Text ( " click pop suspension window " , 
  style: the TextStyle (the fontSize: 20 is ) , 
  Key: anchorKey 
), 

. 3 . Gets coordinates: 
RenderBox renderBox = anchorKey.currentContext.findRenderObject ();
 var offset =   renderBox.localToGlobal (Offset.zero); 

abscissa controls: offset.dx 
ordinate control: offset .dy 

If you want to get control just below the coordinates: 
 RenderBox renderBox = anchorKey.currentContext.findRenderObject ();
  var= renderBox.localToGlobal offset (Offset ( 0.0 , renderBox.size.height)); 

   the abscissa controls below: offset.dx 
   ordinate controls below: offset.dy 

. 4 . Gets size of the control: 
RenderBox renderBox = anchorKey.currentContext. findRenderObject (); 
Final size = renderBox.size;

 7. A network requests where there is substantially md5

dart has built-in md5 encryption package, first introduced the header file:

import 'dart:convert';
import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';

md5 encryption method:

// MD5 encrypted 
String generateMd5 (String Data) {
   var Content = new new Utf8Encoder () Convert (Data);.
   Var Digest = md5.convert (Content);
   // this is actually digest.toString () 
  return hex.encode (Digest .bytes); 
}

8. flutter introduction of image resources

The introduction of a single picture can also be introduced into the entire folder

Guess you like

Origin www.cnblogs.com/joe235/p/11498060.html
Recommended