skip to Main Content

This is my Code i write for my HOME SCREEN When i Hot reload app it becomes white screen. When i simply remove Listview() and Call Only AnimatedPageView() its run perfectly but it not scrollable when i scroll.

import 'package:eads/Screens/HomeScreen/HomeScreen_Elements/Logo_area.dart';
import 'package:flutter/material.dart';

import 'HomeScreen_Elements/pageview.dart';

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          toolbarHeight: 80,
          title: AppLogoButton(),
        ),
        body: ListView(
          children: [AnimatedPageView()],
        ),
      ),
    );
  }
}

AnimatedPageView() Code is 👇

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

import 'Hero_area2.dart';
import 'Hero_area.dart';

class AnimatedPageView extends StatefulWidget {
  @override
  _AnimatedPageViewState createState() => _AnimatedPageViewState();
}

class _AnimatedPageViewState extends State<AnimatedPageView> {
  late PageController _pageController;
  int _currentPage = 0;
  late Timer _timer;

  @override
  void initState() {
    super.initState();
    _pageController = PageController(initialPage: _currentPage);
    _startTimer();
  }

  @override
  void dispose() {
    _pageController.dispose();
    _timer.cancel();
    super.dispose();
  }

  void _startTimer() {
    _timer = Timer.periodic(Duration(seconds: 3), (_) {
      if (_currentPage < 2) {
        _currentPage++;
      } else {
        _currentPage = 0;
      }
      _pageController.animateToPage(
        _currentPage,
        duration: Duration(milliseconds: 1000),
        curve: Curves.easeInOut,
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Image.asset(
            'assets/waveElement2.jpg',
            alignment: Alignment.topCenter,
            height: 600,
            fit: BoxFit.cover,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              for (int i = 0; i < 2; i++)
                AnimatedContainer(
                  duration: Duration(milliseconds: 300),
                  margin: EdgeInsets.symmetric(horizontal: 4),
                  height: 8,
                  width: _currentPage == i ? 24 : 8,
                ),
            ],
          ),
          Container(
            height: 1000,
            child: PageView(
              controller: _pageController,
              onPageChanged: (index) {
                setState(() {
                  _currentPage = index;
                });
              },
              children: [
                HeroArea(),
                HeroArea2(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

I Want to Solve this.. Find Wrong in my code and solve my problem. Experts !! I need your help. Need Clarification about how to shorten these code too.

2

Answers


  1. Just remove the Scaffold Widget from the AnimatedPageView class. and it’ll start working.

    Login or Signup to reply.
  2. use a SingleChildScrollView Instead of Listview
    like:

    Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          toolbarHeight: 80,
          title: AppLogoButton(),
        ),
        body: SingleChildScrollView(
          child:AnimatedPageView(),
        ),
      ),
    );
    

    and remove the Scaffold from AnimatedPageView(),just return the Stack Widget

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search