在下面的代码中,如何修复类型字符串不是类型小部件的子类型

时间:2019-11-04 04:31:44

标签: flutter dart

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

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):以下断言被抛出   Carousel(脏,状态:CarouselState#7c7de):I / flutter(3766):类型   'String'不是'Widget'I / flutter类型的子类型(3766):   I / flutter(3766):任一断言都指示   框架本身,否则我们应该提供大量的I / flutter(   3766):此错误消息中的更多信息可帮助您确定   并解决根本原因。

1 个答案:

答案 0 :(得分:1)

代替图像列表中的字符串:

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