You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Release模式下Stack中部分Widget不显示问题求助

Hey there! Let's break down why some widgets in your Stack layout aren't showing up in Release mode, and fix them step by step:

1. Fix the Invalid Expanded Usage

The most likely culprit here is the misplaced Expanded widget inside a Container. Expanded only works as a direct child of Row, Column, or Flex—using it inside a Container is invalid. Debug mode is lenient about this, but Release mode's strict optimizations will ignore the invalid Expanded, causing your text "এই লেখকের আরও কিছু বই" to disappear.

Fix:

Remove the unnecessary Expanded wrapper:

Container(
  padding: EdgeInsets.only(left: 20, top: 60.0),
  child: Text(
    "এই লেখকের আরও কিছু বই",
    style: TextStyle(
        fontSize: 30,
        fontWeight: FontWeight.bold,
        color: Colors.white),
    overflow: TextOverflow.clip,
  ),
),

2. Add super.dispose() to Your Dispose Method

Your dispose method is missing a call to super.dispose(), which is required to properly clean up the State's resources. In Release mode, this can lead to unexpected layout issues or widget rendering failures.

Fix:

@override
void dispose() {
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitDown,
    DeviceOrientation.portraitUp,
  ]);
  super.dispose(); // Add this critical line
}

3. Add Error Handling to FutureBuilder

Right now, your FutureBuilder only handles loading and success states, but ignores errors. If fetchBooks() throws an exception (e.g., network failure) in Release mode, the widget will just show nothing instead of an error message.

Fix:

FutureBuilder(
  future: fetchBooks(),
  builder: (context, AsyncSnapshot<List<Book>> snapshot) {
    // Handle error state first
    if (snapshot.hasError) {
      return Center(
        child: Text(
          'Failed to load books',
          style: TextStyle(color: Colors.white),
        ),
      );
    }

    if (!snapshot.hasData) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          CircularProgressIndicator(
            backgroundColor: _whiteCream,
          ),
          Text("Loading", style: TextStyle(color: Colors.white)),
        ],
      );
    } else {
      // Your existing code for displaying writer books
      var writterBooks = snapshot.data
          .where((b) => b.author == widget.storyBooksValue.author)
          .toList();
      print(writterBooks.length);
      return ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: writterBooks.length,
        itemBuilder: (context, index) {
          // ... rest of your list item code
        });
    }
  },
),

4. Verify Network Configuration (Just in Case)

Even though you added the INTERNET permission, double-check if your fetchBooks() or image URLs use HTTP (not HTTPS). Android Release mode blocks cleartext HTTP traffic by default. If you need to use HTTP, add this to your android/app/src/main/AndroidManifest.xml:

<application
    ...
    android:usesCleartextTraffic="true">

(Note: Your image URLs are HTTPS, so this might not be the issue, but it's worth confirming.)

5. Check for Tree Shaking Optimizations

Flutter's Release mode tree shaking removes unused code. Ensure that your fetchBooks() function and Book model class are fully used—if any fields (like author or imgUrl) are marked as unused, they might be stripped out, breaking your widget logic.

After applying these fixes, rebuild your app in Release mode and test again—most likely, the missing widgets will start showing up!

内容的提问来源于stack exchange,提问作者Abir Ahsan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 22:42:52