simulator 0.3.4 simulator: ^0.3.4 copied to clipboard
A (not just) device simulator for Flutter. Makes building multi-platform UIs a breeze
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:simulator/simulator.dart';
void main() {
runSimulatorApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.purple),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.purple,
brightness: Brightness.dark,
),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late final _controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
)..repeat(reverse: true);
late final _animation = createSimulatedAnimation(
CurvedAnimation(
parent: _controller,
curve: const Interval(
0.0,
1.0,
curve: Curves.easeInOut,
),
),
label: 'Rotation Animation',
);
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(height: 64.0),
Text(
'Current locale is ${Localizations.localeOf(context)}',
style: Theme.of(context).textTheme.headlineMedium,
),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 64.0),
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return Transform.rotate(
angle: _animation.value * 2 * pi,
child: child,
);
},
child: Container(
width: 200.0,
height: 200.0,
color: Colors.purple,
),
),
const SizedBox(height: 64.0),
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Alert Dialog'),
content: const Text('This is an alert dialog.'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'),
),
],
);
},
);
},
child: const Text('Show Alert Dialog'),
),
const SizedBox(height: 64.0),
InteractiveViewer(
panEnabled: true,
child: Container(
width: 2000.0,
height: 200.0,
color: Colors.black,
child: const GridPaper(),
),
),
..._testContainers,
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
List<Container> get _testContainers => List.generate(
10,
(v) {
if (v % 2 == 0) {
return Container(
height: 200.0,
alignment: Alignment.center,
padding: const EdgeInsets.all(16.0),
child: const TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Enter some text',
),
),
);
}
return Container(
height: 100,
color: Colors.primaries[v % Colors.primaries.length],
);
},
);