2022年9月29日星期四

2022年9月28日星期三

2022年9月26日星期一

image error 404

 Image.network('Your image url...',

    errorBuilder: (BuildContext context, Object exception, StackTrace stackTrace) {
        return Text('Your error widget...');
    },
),

2022年9月23日星期五

iOS防screen shot screen capture

 import UIKit

import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
self.window.makeSecure() //Add this line
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

//And this extension
extension UIWindow {
func makeSecure() {
let field = UITextField()
field.isSecureTextEntry = true
self.addSubview(field)
field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.first?.addSublayer(self.layer)
}
}

2022年9月22日星期四

check if in Scaffold

 (){

  try{
Scaffold.of(context);
}catch(e){
//not in Scaffold
}
return Container();
}()

When the keyboard appears, => Overflow , the Flutter widgets resize. How to prevent this?

Updated Answer

resizeToAvoidBottomPadding is now deprecated.

The updated solution is to set resizeToAvoidBottomInset property to false.


Original Answer

In your Scaffold, set resizeToAvoidBottomPadding property to false.


2022年9月21日星期三

Yellow lines under Text Widgets in Flutter?

 DefaultTextStyle(

  style: TextStyle(...),
  child: Text('Hello world'),
)

get object position on screen

extension GlobalKeyExtension on GlobalKey {
  Rect? get globalPaintBounds {
    final renderObject = currentContext?.findRenderObject();
    final translation = renderObject?.getTransformTo(null).getTranslation();
    if (translation != null && renderObject?.paintBounds != null) {
      final offset = Offset(translation.x, translation.y);
      return renderObject!.paintBounds.shift(offset);
    } else {
      return null;
    }
  }
}




final containerKey = GlobalKey();

Container(
  key: containerKey,
  width: 100,
  height: 50,
)

containerKey.globalPaintBounds

MeasureSize measuredsize measure size

https://pub.dev/packages/measured_size

Error (Xcode): no --inputencoding specified and could not detect encoding from input file ios/Runner/zh_Hant.lproj/InfoP list.strings:0:0

step 1. change to UTF-8 (if the file error)

step 2. copy and paste some dummy content


"New" = "New";

"In Progress" = "In Progress";

"Waiting" = "Waiting";

"Closed" = "Closed";

2022年9月8日星期四

Force Flutter navigator to reload state when popping

Short answer:

Use this in 1st page:

Navigator.pushNamed(context, '/page2').then((_) => setState(() {}));

and this in 2nd page:

Navigator.pop(context);