screenshooter 1.0.2 copy "screenshooter: ^1.0.2" to clipboard
screenshooter: ^1.0.2 copied to clipboard

Automatically create screenshots of your flutter app

example/lib/main.dart

import 'package:flutter/material.dart';

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

final rootNavigatorKey = GlobalKey<NavigatorState>();
final appKey = GlobalKey<_MyAppState>();

Locale locale = const Locale('en', 'US');
List<Locale> locales = [
  const Locale('en', 'US'),
  const Locale('de', 'DE'),
];

void setLocale(Locale l) {
  locale = l;
  appKey.currentState?.restart();
}

class MyApp extends StatefulWidget {
  MyApp() : super(key: appKey);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Key key = UniqueKey();

  void restart() {
    setState(() {
      key = UniqueKey();
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Screenshooter Demo',
      key: key,
      navigatorKey: rootNavigatorKey,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(
          seedColor: locale.countryCode == 'US' ? Colors.blue : Colors.green,
        ),
        useMaterial3: true,
      ),
      routes: {
        '/': (context) => const CustomPage(
              title: 'Home Page',
              isHome: true,
            ),
        '/other': (context) => const CustomPage(
              title: 'Other Page',
              isHome: false,
            ),
      },
    );
  }
}

class CustomPage extends StatelessWidget {
  final String title;
  final bool isHome;

  const CustomPage({
    super.key,
    required this.title,
    required this.isHome,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              'Locale: $locale',
              style: Theme.of(context).textTheme.titleLarge,
            ),
            TextButton(
              onPressed: () {
                setLocale(locales.firstWhere((element) => element != locale));
              },
              child: Text(
                'Switch to ${locales.firstWhere((element) => element != locale)}',
              ),
            ),
            if (isHome)
              ElevatedButton(
                onPressed: () {
                  rootNavigatorKey.currentState!.pushNamed('/other');
                },
                child: const Text('Go to other page →'),
              ),
          ],
        ),
      ),
    );
  }
}
2
likes
150
pub points
0%
popularity

Publisher

verified publisherlojewski.dev

Automatically create screenshots of your flutter app

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

archive, args, checked_yaml, flutter, glob, image, yaml

More

Packages that depend on screenshooter