【问题标题】:how to fix type string is not a subtype of type widget in below flutter code如何修复类型字符串不是下面颤动代码中类型小部件的子类型
【发布时间】:2020-02-29 09:40:50
【问题描述】:

这是我在应用程序中添加轮播滑块的代码

homescreen.dart

import 'package:eat_healthy/caroslider.dart';
import 'package:flutter/material.dart';
import 'package:gradient_app_bar/gradient_app_bar.dart';
import 'package:share/share.dart';
import 'package:eat_healthy/drawer.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:dynamic_theme/theme_switcher_widgets.dart';





class HomeScreen extends StatefulWidget {
  HomeScreen({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: GradientAppBar(
        gradient: LinearGradient(
            colors: [Colors.deepPurple, Colors.deepPurpleAccent, Colors.purple]),
        actions: <Widget>[
          IconButton(
              icon: Icon(
                Icons.share,
                color: Colors.white,
              ),
              onPressed: () {
                Share.share('Installl this app to know about health benefits of apple ');
              })
        ],
      ),
      drawer: AppDrawer(),
      body: Stack(
        fit: StackFit.expand,
        children: <Widget>[

 CaroSlider() 

        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: showChooser,
        child: const Icon(Icons.add),
      ),);

  }

  void showChooser() {
    showDialog<void>(
        context: context,
        builder: (context) {
          return BrightnessSwitcherDialog(
            onSelectedTheme: (brightness) {
              DynamicTheme.of(context).setBrightness(brightness);
            },
          );
        });
  }


}

Caroslider.dart

import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/material.dart';




final myCarousel = Carousel(
  dotSize: 5.0,
  dotIncreaseSize: 2.0,
  borderRadius: true,
  radius: Radius.circular(10.0),
  animationCurve: Curves.easeInOut,
  animationDuration: Duration(seconds: 2),
  images: [
    'https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80',
    'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',
    'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
    'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
    'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
    'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80',
  ],
);








class CaroSlider extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: EdgeInsets.symmetric(vertical: 15.0),
        child:myCarousel
        );
  }
}                                                   

Caroslider 代码有什么问题。

I/flutter (3766):以下断言被抛出构建 轮播(脏,状态:CarouselState#7c7de):I/flutter(3766):类型 'String' 不是 'Widget' I/flutter 类型的子类型(3766): I/flutter (3766): 任何一个断言都表示在 框架本身,或者我们应该提供大量的 I/flutter ( 3766):此错误消息中的更多信息可帮助您确定 并解决根本原因。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    而不是图像列表中的字符串:

    images:[
        Image.network('your url'),
        Image.network('your url'),
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 2021-08-22
      • 2020-10-28
      • 2019-06-08
      • 2020-02-23
      • 1970-01-01
      相关资源
      最近更新 更多