首页 > 解决方案 > 寻呼机指示器颤动

问题描述

我正在使用page_indicator: ^0.1.3插件来显示页面视图的指示器。

PageIndicatorContainer(
          pageView: PageView.builder(
            controller: PageController(),
            itemBuilder: (context, position) {
         );
            },
            scrollDirection: Axis.horizontal,
            itemCount: widgetView.widgetItemList.length,
          ),
          align: IndicatorAlign.bottom,
          length: widgetView.widgetItemList.length,
          indicatorColor: Colors.white,
          indicatorSelectorColor: Colors.grey,
          size: 5.0,
          indicatorSpace: 10.0,
      ))

但它会在图像上显示指示符。

在此处输入图像描述

我没有找到任何选项或插件来设置图像下方的指示器,例如

在此处输入图像描述

标签: androidflutter

解决方案


PageIndicatorContainer似乎没有可以在外部设置指标的属性PageView。这种情况的解决方法是在PageView.

演示

完整样本

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  PageController controller;
  GlobalKey<PageContainerState> key = GlobalKey();

  @override
  void initState() {
    super.initState();
    controller = PageController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Flexible(
            flex: 5,
            child: PageIndicatorContainer(
              key: key,
              child: PageView.builder(itemCount: 4,itemBuilder: (context, position) {
                return Container(
                  // Padding will help prevent overlap on the page indicator
                  padding: EdgeInsets.fromLTRB(5, 5, 5, 30),
                  child: Container(
                    color: Colors.greenAccent,
                    child: Center(child: Text('${position + 1}')),
                  ),
                );
              }),
              align: IndicatorAlign.bottom,
              length: 4,
              indicatorSpace: 20.0,
              padding: const EdgeInsets.all(10),
              indicatorColor: Colors.grey,
              indicatorSelectorColor: Colors.blue,
              shape: IndicatorShape.circle(size: 12),
            ),
          ),
          Flexible(flex: 1, child: Container()),
          Flexible(
              flex: 5,
              child: Container(
                color: Colors.cyan,
              ))
        ],
      ),
    );
  }
}

推荐阅读