skip to Main Content

I am not sure why the issue is coming to the code, I have tried multiple fixes but nothing is working and the similar kind of issue is with other parts of the project too. I am not sure how to fix it, it already has Build Context in Widget still I am not sure what it is lacking.

Missing concrete implementation of ‘State.Widget’.
Try implementing the missing method, or make the class abstract.dartnon_abstract_class_inherits_abstract_member
class _MonthDateRowState extends State
package:study_sync/Pages/home.dart

class MonthDateRow extends StatefulWidget {
  @override
  State<MonthDateRow> createState() => _MonthDateRowState();
}

class _MonthDateRowState extends State<MonthDateRow> {
  late ApiService _apiService;
  late TokenStorageService _tokenStorageService;
  List<VideoModel>? _videos;
  bool _isLoading = true;
  String? _errorMessage;

  @override
  void initState() {
    super.initState();
    _tokenStorageService = TokenStorageService();
    _apiService = ApiService(
      'https://fe00-117-220-236-245.ngrok-free.app/api',
      _tokenStorageService,
    );
    _fetchData();
  }

  Future<void> _fetchData() async {
    setState(() => _isLoading = true);
    try {
      final token = await _tokenStorageService.getToken() ?? '';
      final fetchedVideos = await _apiService.fetchVideos(token);
      setState(() {
        _videos = fetchedVideos.cast<VideoModel>();
        _isLoading = false;
      });
    } catch (error) {
      setState(() {
        _isLoading = false;
        _errorMessage = error.toString();
      });
    }
  }

  List<DateTime> _getNextDates(int count) {
    return List.generate(
      count,
      (index) => DateTime.now().add(Duration(days: index)),
    );
  }

  
  Widget Build(BuildContext context) {
    if (_isLoading) {
      return _loadingWidget();
    } else if (_errorMessage != null) {
      return _errorWidget();
    } else if (_videos == null || _videos!.isEmpty) {
      return _emptyWidget();
    } else {
      return _videosWidget();
    }
  }

  Widget _loadingWidget() {
    return Scaffold(
      appBar: AppBar(title: Text('Scheduled Videos')),
      body: Center(child: CircularProgressIndicator()),
    );
  }

  Widget _errorWidget() {
    return Scaffold(
      appBar: AppBar(title: Text('Error')),
      body: Center(child: Text(_errorMessage!)),
    );
  }

  Widget _emptyWidget() {
    return Scaffold(
      appBar: AppBar(title: Text('Scheduled Videos')),
      body: Center(child: Text('No scheduled videos found')),
    );
  }

  Widget _videosWidget() {
    final dateList = _getNextDates(20);
    int videoIndex = 0;
    return Scaffold(
      appBar: AppBar(title: Text('Scheduled Videos')),
      body: ListView.builder(
        itemCount: dateList.length,
        itemBuilder: (context, index) {
          final date = dateList[index];
          final video = _videos![videoIndex % _videos!.length];
          videoIndex++;

          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                  DateFormat('EEEE, MMMM d').format(date),
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                ),
              ),
              _buildScheduledVideo(context, video),
            ],
          );
        },
      ),
    );
  }

  Widget _buildScheduledVideo(BuildContext context, VideoModel video) {
    return Card(
      margin: EdgeInsets.only(bottom: 8),
      child: ListTile(
        leading: Icon(Icons.video_library),
        title: Text(
          video.title,
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
        subtitle: Text(video.videoUrl),
        trailing: Text(DateFormat.jm().format(video.scheduledDate)),
      ),
    );
  }
}

Please suggest a fix

2

Answers


  1. You are missing the implementation of the abstract build method

    That’s what you have done, but it’s not the build method.

      Widget Build(BuildContext context) {
        if (_isLoading) {
          return _loadingWidget();
        } else if (_errorMessage != null) {
          return _errorWidget();
        } else if (_videos == null || _videos!.isEmpty) {
          return _emptyWidget();
        } else {
          return _videosWidget();
        }
      }
    

    Fix

    Modify the method signature like this

    @override
    Widget build(BuildContext context) {}
    

    Hope it helps you.

    Login or Signup to reply.
  2. build is method name not class name always use. you need to change method name also use @override:
    from this:

    Widget Build(BuildContext context) {}

    to this:

    @override
    Widget build(BuildContext context) {}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search