Flutter填坑

flutter插件官网地址:https://pub.dartlang.org/packages/

设置导航栏颜色透明

需要同时设置Colors.transparent和elevation

appBar: AppBar(
    backgroundColor: Colors.transparent,
    elevation: 0,//设置导航栏颜色透明
),

显示隐藏控件

Visibility(
    visible: true,
    child: Widget(),
)

设置圆角

ClipRRect(
    child: Container(
       height: 56,
       alignment: Alignment.center,
       color: Colors.white,
       child: Text(
           '退出登录',
           style: TextStyle(fontSize: 15, color: BaseColor.colorFF262626),
       ),
     ),
     borderRadius: BorderRadius.circular(8),//圆角角度
 ),

设置状态栏字体颜色

Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: SystemUiOverlayStyle.dark,//设置状态栏字体黑色
      child: MaterialApp(
        title: 'Flutter Demo',
        debugShowCheckedModeBanner: false,
        initialRoute: '/',
        onGenerateRoute: onGenerateRoute,
      ),
    );
  }
AppBar(
    brightness: Brightness.light,//设置状态栏字体黑色
    backgroundColor: Colors.transparent,
    elevation: 0, //设置导航栏颜色透明
    title: Text('企业简介'),
	centerTitle: false,
  ),

Flutter 项目语言为OC引入的库为swift报错

ld: warning: Could not find or use auto-linked library ‘swiftCoreGraphics’

解决方式 :https://www.jianshu.com/p/488f410a17fc
OC与swift混编:https://www.jianshu.com/p/488f410a17fc

图片名称尽量使用英文

报错

Image provider: AssetImage(bundle: null, name: "assets/images/icons/价签申领.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#f44b4(), name: "assets/images/icons/价签申领.png", scale: 1.0)

排除了pubspec.yaml中引用问题后,将“价签申领.png”图片名改为英文后问题解决

Vertical viewport was given unbounded height.

Column里面嵌套Column、ListView、EasyRefresh等空间具有无限延展性等控件,每一层都需要用Expanded包裹,漏掉一层都不行。

Column(children:<Widget>[
  SearchBar(),
  Expanded(//加上
  child:EasyRefresh(
      child:ListView()
    )
  )
 ]
)

Incorrect use of ParentDataWidget

Expanded、Flexible只在Row、Column等组件内,不在其他组件内使用。

ListView里面嵌套GridView 导致显示错误及无法滚动问题

报错
Vertical viewport was given unbounded height.

解决方式

pod文件报错 set use_modular_headers!

The Swift pod barcode_scan depends upon MTBBarcodeScanner, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies

在pod文件中添加这句:use_modular_headers!

target 'Runner' do
  # Flutter Pod
  use_frameworks!
  
  copied_flutter_dir = File.join(__dir__, 'Flutter')
  copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
  copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
  unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)

如果想要在Column中使用ListView.需要对ListView的外面包裹一层:Expanded

修改TextField高度

new TextField(
          decoration: InputDecoration(
            contentPadding: const EdgeInsets.symmetric(vertical: 10.0),
          ),
        )

如果TextField的有设置prefixIcon ,就还需要使用ConstrainedBox

class SearchPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 16, right: 16, bottom: 10),
      child: ConstrainedBox(
        constraints: BoxConstraints(maxHeight: 35),
        child: TextField(
          enabled: false,
          style: BaseTextStyle.style595959_14,
          decoration: InputDecoration(
            contentPadding: const EdgeInsets.symmetric(vertical: 4.0),
            fillColor: BaseColor.colorFFF5F5F5,
            filled: true,
            border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(4),
                borderSide: BorderSide.none),
            hintText: '请输入门店账号/门店名称', //占位字符
            hintStyle: BaseTextStyle.style999999_14, //占位字符样式
            prefixIcon: ImageIcon(
              IconUtils.getAssetIcon('sousuomendian'),
              color: ColorRes.COLOR_595959,
            ),
          ),
        ),
      ),
    );
  }
}

Error 105 received from application: Isolate must be runnable

Error 105 received from application: Isolate must be runnable
Hot reload received invalid response: {code: 105, message: Isolate must be runnable, data: {request: {method: _reloadSources, params: {pause: false, rootLibUri:
file:///Users/edz/Library/Developer/CoreSimulator/Devices/74C78E3B-0DEA-4D2B-8442-95F415EF0F14/data/Containers/Data/Application/8A1C31EC-7229-4B50-AE5F-88C223BCCF50/tmp/flutter_mixedAeuAuy/flutter_mixed/li
b/main.dart.incremental.dill, packagesUri:
file:///Users/edz/Library/Developer/CoreSimulator/Devices/74C78E3B-0DEA-4D2B-8442-95F415EF0F14/data/Containers/Data/Application/8A1C31EC-7229-4B50-AE5F-88C223BCCF50/tmp/flutter_mixedAeuAuy/flutter_mixed/.p
ackages, isolateId: isolates/3504661799683503}}, details: Isolate must be runnable before this request is made.}}

原因1 :Flutter当前资源与build缓存中的不匹配 解决:删除build文件夹,重建

flutter build ios-framework

原因2:项目中有两个FlutterViewController 解决:删除其中一个
在我的项目中通过VSCode创建的项目,flutter会自动创建一个带main.storeboard的iOS项目,而main.storeboard里面有一个FlutterViewController。我自己又创建了一个基于FlutterViewController的类,来统一管理了flutter与原生的交互。所以出了上述问题。具体解决方式我删除了main.storeboard,并且改造了didFinishLaunchingWithOptions方法

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    /** 设置主控制器继承FlutterViewController*/
    MainViewController * VC = [[MainViewController alloc]init];
    BaseNavigationController * NVC = [[BaseNavigationController alloc]initWithRootViewController:VC];
    [self.window setRootViewController:NVC];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

widget宽度撑满父空间

Container(
  color: Colors.red,
  width: MediaQuery.of(context).size.width,
  child: Text("宽度撑满父空间"),
)
Container(
  color: Colors.red,
  width: double.infinity,
  child: Text("同上"),
)

- 报错: setState() or markNeedsBuild() called during build

原因就是, 在build的时候不允许调用setState() 或markNeedsBuild().

错误代码

@override
  void initState() {
    super.initState();
    requestListData();
  }

  void requestListData() {
    Toasts.showLoading(context, '请求数据...');
  }

修改后

@override
void initState() {
  super.initState();
  WidgetsBinding.instance.addPostFrameCallback((_) {
    requestListData();
  });
}

void requestListData() {
  Toasts.showLoading(context, '请求数据...');
}

保持页面状态使用 IndexedStack

解决方式

An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.

Row包含Textfield时错误的解决办法
解决方式

VSCode弹出:Error: Emulator didn’t connect within 60 seconds

方法1:
打开Android Studio  ->工具-> AVD管理器 ->虚拟设备->操作->单击"停止" 
重启模拟器,重启VSCode

方法2:
打开Android Studio  ->工具-> AVD管理器 ->虚拟设备->操作->单击"擦除数据" 
重启模拟器,重启VSCode
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值