surveyjs_flutter 0.1.1 copy "surveyjs_flutter: ^0.1.1" to clipboard
surveyjs_flutter: ^0.1.1 copied to clipboard

A Flutter package for rendering SurveyJS forms with support for all question types including dynamic panels, matrix questions, and media inputs.

example/lib/main.dart

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

import 'survey_examples.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter SurveyJS Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: Colors.teal,
          secondary: Colors.orange,
        ),
        useMaterial3: true,
        scaffoldBackgroundColor: const Color(0xFFF0F4F8),
        appBarTheme: const AppBarTheme(
          centerTitle: true,
          elevation: 4,
          shadowColor: Colors.black26,
        ),
        inputDecorationTheme: const InputDecorationTheme(
          filled: true,
          fillColor: Colors.white,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.all(Radius.circular(16)),
            borderSide: BorderSide.none,
          ),
          focusedBorder: OutlineInputBorder(
            borderRadius: BorderRadius.all(Radius.circular(16)),
            borderSide: BorderSide(color: Colors.teal, width: 2),
          ),
          contentPadding: EdgeInsets.symmetric(horizontal: 20, vertical: 16),
        ),
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
            backgroundColor: Colors.teal,
            foregroundColor: Colors.white,
            elevation: 2,
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
            shape: const StadiumBorder(),
          ),
        ),
      ),
      home: const SurveyListScreen(),
    );
  }
}

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

  static const List<Color> _cardColors = [
    Colors.blue,
    Colors.teal,
    Colors.orange,
    Colors.purple,
    Colors.indigo,
    Colors.green,
    Colors.pink,
    Colors.amber,
  ];

  @override
  Widget build(BuildContext context) {
    final surveys = SurveyExamples.all();

    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter SurveyJS Examples'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: ListView.builder(
        padding: const EdgeInsets.all(16),
        itemCount: surveys.length + 1,
        itemBuilder: (context, index) {
          if (index == 0) {
            return const Padding(
              padding: EdgeInsets.only(bottom: 16),
              child: Text(
                'Select an example below to view the rendered SurveyJS form.',
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
              ),
            );
          }

          final item = surveys[index - 1];
          final survey = item['survey'] as Map<String, dynamic>;
          final themePreset = item['themePreset'] is SurveyThemePreset
              ? item['themePreset'] as SurveyThemePreset
              : null;
          final uiLabels = item['uiLabels'] is SurveyUiLabels
              ? item['uiLabels'] as SurveyUiLabels
              : null;
          final color = _cardColors[(index - 1) % _cardColors.length];

          return _buildSurveyCard(
            context,
            title: survey['title']?.toString() ?? 'Untitled Survey',
            description: survey['description']?.toString() ?? '',
            color: color,
            onTap: () => _navigateToSurvey(
              context,
              survey,
              themePreset,
              uiLabels,
            ),
          );
        },
      ),
    );
  }

  Widget _buildSurveyCard(
    BuildContext context, {
    required String title,
    required String description,
    required Color color,
    required VoidCallback onTap,
  }) {
    return Card(
      margin: const EdgeInsets.only(bottom: 12),
      elevation: 2,
      child: InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(12),
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Row(
            children: [
              Container(
                padding: const EdgeInsets.all(12),
                decoration: BoxDecoration(
                  color: color.withValues(alpha: 0.1),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Icon(Icons.dynamic_form, color: color, size: 32),
              ),
              const SizedBox(width: 16),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      title,
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    if (description.isNotEmpty) ...[
                      const SizedBox(height: 4),
                      Text(
                        description,
                        style: TextStyle(fontSize: 13, color: Colors.grey[600]),
                      ),
                    ],
                  ],
                ),
              ),
              const SizedBox(width: 8),
              const Icon(Icons.arrow_forward_ios, size: 16),
            ],
          ),
        ),
      ),
    );
  }

  void _navigateToSurvey(
    BuildContext context,
    Map<String, dynamic> surveyJson,
    SurveyThemePreset? themePreset,
    SurveyUiLabels? uiLabels,
  ) {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => SurveyScreen(
          config: SurveyConfig(
            surveyJson: surveyJson,
            themePreset: themePreset,
            uiLabels: uiLabels,
            onComplete: (result) {
              debugPrint('Survey completed: ${result.toSnapshotJson()}');
            },
            showDebugLogs: false,
          ),
        ),
      ),
    );
  }
}
1
likes
140
points
123
downloads

Documentation

API reference

Publisher

verified publisherelvynforge.xyz

Weekly Downloads

A Flutter package for rendering SurveyJS forms with support for all question types including dynamic panels, matrix questions, and media inputs.

Homepage

License

MIT (license)

Dependencies

file_picker, flutter, flutter_html, flutter_js, flutter_svg, image, image_picker, mime, signature

More

Packages that depend on surveyjs_flutter