Arfmann
Arfmann

Reputation: 734

Flutter - Display days of a month starting from current day

I have a ListView() with horizontal scrolling. In this ListView I should display all the days of current month (without month name) starting from current day (which should be highlighted).

It should look like this:

enter image description here

Upvotes: 0

Views: 2549

Answers (2)

Magnuti
Magnuti

Reputation: 165

Take a look at the Weekly Date Picker package, it may be exactly what you are looking for.

Upvotes: 0

chunhunghan
chunhunghan

Reputation: 54365

You can fork and use package https://pub.dev/packages/date_picker_timeline
And remark month code in date_widget.dart

/*Text(new DateFormat("MMM", locale).format(date).toUpperCase(), // Month
              style: monthTextStyle),*/

enter image description here

working demo

enter image description here

full example code

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Page1(title: 'Date Picker Timeline Demo'),
    );
  }
}

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

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

class _Page1State extends State<Page1> {
  DateTime _selectedValue = DateTime.now();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Container(
          padding: EdgeInsets.all(20.0),
          //color: Colors.blueGrey[100],
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("You Selected:"),
              Padding(
                padding: EdgeInsets.all(10),
              ),
              Text(_selectedValue.toString()),
              Padding(
                padding: EdgeInsets.all(20),
              ),
              DatePickerTimeline(
                _selectedValue,
                onDateChange: (date) {
                  // New date selected
                  setState(() {
                    _selectedValue = date;
                  });
                },
              ),
            ],
          ),
        ));
  }
}

Upvotes: 1

Related Questions