Skip to main content

flutter_dev_setup 0.2.3 copy "flutter_dev_setup: ^0.2.3" to clipboard
flutter_dev_setup: ^0.2.3 copied to clipboard

A developer setup screen for Flutter apps: find dev servers on the local network, switch the API base URL at runtime, and keep the choice across launches.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dev_setup/flutter_dev_setup.dart';

const defaultBaseUrl = 'https://example.com/api/v1/';

final apiBaseUrl = ValueNotifier<String>(defaultBaseUrl);

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (kDebugMode) {
    final saved = await DevSetup.savedBaseUrl();
    if (saved != null && await DevSetup.isReachable(saved)) {
      apiBaseUrl.value = saved;
    }
  }
  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter_dev_setup example',
      home: kDebugMode
          ? DevSetupScreen(
              defaultBaseUrl: defaultBaseUrl,
              onBaseUrlChanged: (url) => apiBaseUrl.value = url,
              onProceed: (context) => Navigator.of(context).pushReplacement(
                MaterialPageRoute<void>(builder: (_) => const HomePage()),
              ),
            )
          : const HomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home')),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24),
          child: ValueListenableBuilder<String>(
            valueListenable: apiBaseUrl,
            builder: (context, url, _) => Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(
                  'API base URL',
                  style: Theme.of(context).textTheme.labelLarge,
                ),
                const SizedBox(height: 8),
                SelectableText(url, textAlign: TextAlign.center),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
160
points
608
downloads
screenshot

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A developer setup screen for Flutter apps: find dev servers on the local network, switch the API base URL at runtime, and keep the choice across launches.

Repository (GitHub)
View/report issues

Topics

#developer-tools #networking #debugging

License

MIT (license)

Dependencies

device_info_plus, flutter, shared_preferences

More

Packages that depend on flutter_dev_setup