T. Tim
T. Tim

Reputation: 25

Firestore flutter app gets error after 2 seconds?

I'm using the flutter_calendar_carousel package for my planner app. I'm getting the data from firestore so it shows up for like 2 seconds and then I get this error "package:flutter/src/widgets/container.dart': Failed assertion: line 316 pos 15: 'padding == null || padding.isNonNegative': is not true."

This is my code.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart' show CalendarCarousel;
import 'package:flutter_calendar_carousel/classes/event.dart';
import 'package:flutter_calendar_carousel/classes/event_list.dart';
import 'package:intl/intl.dart' show DateFormat;


bool onDarkMode = false;

class MonthPageTest extends StatefulWidget {
  @override
  _MonthPageTestState createState() => _MonthPageTestState();
}

class _MonthPageTestState extends State<MonthPageTest> {




  final databaseReference = Firestore.instance.collection("Planerino").document("UserSettings");
  final databaseRef = Firestore.instance.collection("Eventhmonth");



  darkmode() async{
    try {
      databaseReference.updateData({'Darkmode': onDarkMode});
    }catch (e) {
      print(e.toString());
    }
  }


  @override
  void initState(){
    super.initState();
  }

  @override
  void dispose(){
    super.dispose();
  }


    toggleButton(){
    setState(() {
      onDarkMode = !onDarkMode;
    });
    darkmode();
    }

    //calender
    DateTime _currentDate = DateTime.now();


    static Widget _eventIcon = new Container(
      width: 40.0,
      height: 40.0,
    decoration: new BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(1000)),
        border: Border.all(color: Colors.blue, width: 6.0)),
    child: new Icon(
      Icons.person,
      color: Colors.amber,
      size: 40.0,
    ),
  );



  //function
    EventList<Event> _markedDateMap = new EventList<Event>(
    events: {
      new DateTime(2020, 6, 24): [
        new Event(
          date: new DateTime(2020, 6, 13),
          icon: _eventIcon,
          dot: Container(
            margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
            color: Colors.red,
            ),
          ),
        ],
      },
    );


  Widget builderino(BuildContext context){
    return StreamBuilder(
      stream: databaseRef.snapshots(),
      builder: (context, dataSnapshot){
          var ref = dataSnapshot.data.documents;
          for (var i = 0; i < ref.length; i++) {
            String valueString = ref[i]['color'].split('(0x')[1].split(')')[0];
              int value = int.parse(valueString, radix: 16);
              Color newColor = new Color(value);
            _markedDateMap.add(new DateTime(ref[i]['year'], ref[i]['month'], ref[i]['day']), 
            Event(
              date: new DateTime(2020, 6, 13),
              icon: _eventIcon,
              dot: Container(
                child: Padding(
                padding: EdgeInsets.only(top: 90.0),
                child: Container( alignment: Alignment.center, child: Text(ref[i]['description'], style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.w300), textAlign: TextAlign.center,)),
                  ),
                margin: EdgeInsets.symmetric(horizontal: 10.0, vertical: 10.0),
                decoration: BoxDecoration(color: newColor),
                ),
            ));
          }

          return CalendarCarousel<Event>(
        onDayPressed: (DateTime date, List<Event> events) {
          this.setState(() => _currentDate = date);
          events.forEach((event) => print(event.title));
        },
        weekendTextStyle: TextStyle(
          color: Colors.red,
          fontSize: 28.0,
        ),
        markedDatesMap: _markedDateMap,
        markedDateIconBuilder: (event) {
        return event.dot;
      },
        showIconBehindDayText: true,
        markedDateShowIcon: true,
        markedDateIconMaxShown: 1000,
        todayButtonColor: Colors.black12,
        markedDateMoreShowTotal: true,
        headerTextStyle: TextStyle(fontSize: 34.0, color: Colors.blue[300]),
        daysTextStyle: TextStyle(fontSize: 28.0, color: onDarkMode ? Colors.white : Colors.black45),
        todayTextStyle: TextStyle(fontSize: 28.0, color: onDarkMode ? Colors.white : Colors.black45),
        weekdayTextStyle: TextStyle(fontSize: 28.0),
        );
        }
      );
    }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
    body: Container(
      color: onDarkMode ? Colors.black87 : Colors.white,
      margin: EdgeInsets.symmetric(horizontal: 16.0),
      child:  builderino(context),
    ),
    );
  }
}

Do i need to make it async or what is the problem?

Upvotes: 0

Views: 262

Answers (1)

griffins
griffins

Reputation: 8246

from this SO answer TLDR

Flutter has a sophisticated but effective algorithm for rendering its widgets. Margins and Paddings are analyzed at runtime, and the final size and position of the widget is determined. When you try to issue a negative margin you are purposefully creating a not valid layout where a widget is somehow dropping out of the space it is supposed to occupy.

Consider reading the doc here.

Upvotes: 2

Related Questions