simple_polls 1.0.0 copy "simple_polls: ^1.0.0" to clipboard
simple_polls: ^1.0.0 copied to clipboard

outdated

A simple polls widget is simple widget with language localizations.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primaryColor: Colors.indigo),
      debugShowCheckedModeBanner: false,
      home: ExampleApp(),
    );
  }
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text(
          'Polls Widget',
          style: TextStyle(fontSize: 14, color: Colors.white),
        ),
        centerTitle: true,
        toolbarHeight: 40,
      ),
      body: Container(
        child: SimplePollsWidget(
          /// onSelection will be triggered when users presses a option or presses undo button(only available on editable polls).
          /// This function will be called after all the calculation like reducing total polls and marking previous option not selected.
          /// It returns the PollFrameModel .Use this function to do some extra operations like storing this poll into other variable.
          onSelection: (PollFrameModel model) {
            print(model.totalPolls);
          },

          /// optionsStyle will have style used in options.
          optionsStyle: TextStyle(
            fontSize: 13,
            fontWeight: FontWeight.w500,
            color: Theme.of(context).primaryColor,
          ),

          /// languageCode will be used to translate some text used in status like total polls, Poll end time, Undo button.
          /// Allowed values are it,fr,es,gr,en where en is default.
          /// For more language support add translations for that language code in translations/translations.dart and widgets/poll_status.dart.
          /// Add timeago.setLocaleMessages('it', timeago.ItMessages()); to register locales for timeago/remaining in widgets/poll_status.dart.
          /// Add 'es': 'deshacer' to maps present in translations/translations.dart for other translations.
          languageCode: 'it',

          /// Content Padding inside polls widget.
          padding: EdgeInsets.all(15),

          /// Margin for polls widget.
          margin: EdgeInsets.all(15),

          /// Data to be passed to polls widget.
          model: PollFrameModel(
            /// Title of the widget.
            title: Container(
              alignment: Alignment.centerLeft,
              child: Text(
                'Questo è il titolo del sondaggio. Questo è il titolo del sondaggio. Questo è il titolo del sondaggio.',
                style: TextStyle(
                  fontSize: 14,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            totalPolls: 100,

            /// Poll end time
            endTime: DateTime.now().toUtc().add(Duration(days: 10)),

            /// If user hasVoted then results screen will show up.
            hasVoted: false,

            /// If poll is editable then undo button will appear in results screen to participate in poll again.
            editablePoll: true,
            options: <PollOptions>[
              /// Configure options here
              PollOptions(
                label: "opzione 1",
                pollsCount: 40,

                /// Polls received by that option.
                isSelected: false,

                /// If poll selected.
                id: 1,

                /// Option id.
              ),
              PollOptions(
                label: "opzione 2",
                pollsCount: 25,
                isSelected: false,
                id: 2,
              ),
              PollOptions(
                label: "opzione 3",
                pollsCount: 35,
                isSelected: false,
                id: 3,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
18
likes
0
pub points
75%
popularity

Publisher

unverified uploader

A simple polls widget is simple widget with language localizations.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, timeago

More

Packages that depend on simple_polls