mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 01:05:36 +00:00
refactor: split app wrapper from focused example code (multi-file apps)
Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap; a new lib/example.dart holds the full entry screen and focused example code, importing existing supporting files (screens/, tabs/, services/, models/, widgets/, utils/). Apps: analytics_integration, animation_example, biometrics, bottom_sheet, custom_home_drawer, google_signin, grid_layout, handling_routes, image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar, using_custom_fonts, using_listview, using_listwheelscrollview, using_platform_adaptive, view_pdf_file
This commit is contained in:
123
using_platform_adaptive/lib/example.dart
Normal file
123
using_platform_adaptive/lib/example.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
// Example: Platform adaptive widgets
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:using_platform_adaptive/common_widgets/adaptive_button.dart';
|
||||
import 'package:using_platform_adaptive/common_widgets/adaptive_date_picker.dart';
|
||||
import 'package:using_platform_adaptive/common_widgets/adaptive_indicator.dart';
|
||||
|
||||
class Example extends StatefulWidget {
|
||||
const Example({super.key, this.title = 'Using Platform Adaptive'});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<Example> createState() => _ExampleState();
|
||||
}
|
||||
|
||||
class _ExampleState extends State<Example> {
|
||||
TargetPlatform? selectedPlatform;
|
||||
final String introText = "Flutter's flagship feature is it's ability to write"
|
||||
" code once and have it run on multiple devices. While this is great, sometimes"
|
||||
" you want the user interface to look more native to its platform. This project"
|
||||
" showcases the Platform Adaptive pattern, a powerful pattern that allows you"
|
||||
" to create widgets that you write once and look natural on any device. The"
|
||||
" demo is just set up to work on android and iOS but can be extended to work"
|
||||
" on web, native and any other platform flutter supports.";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final platforms = {
|
||||
"Default": null,
|
||||
"Android": TargetPlatform.android,
|
||||
"iOS": TargetPlatform.iOS,
|
||||
};
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(30),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(introText),
|
||||
const SizedBox(height: 30),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Force a platform: "),
|
||||
DropdownButton(
|
||||
value: selectedPlatform,
|
||||
items: List<DropdownMenuItem>.from(platforms.entries.map(
|
||||
(e) => DropdownMenuItem(
|
||||
value: e.value, child: Text(e.key)))),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedPlatform = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Buttons: "),
|
||||
AdaptiveButton(
|
||||
forcePlatform: selectedPlatform,
|
||||
color: Colors.teal,
|
||||
onPressed: () {},
|
||||
child: const Text("I'm a button"),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Dialogs: "),
|
||||
AdaptiveButton(
|
||||
forcePlatform: selectedPlatform,
|
||||
color: Colors.teal,
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AdaptiveDialog(
|
||||
title: "Test",
|
||||
content: const Text("This is the content area"),
|
||||
actions: [
|
||||
AdaptiveDialogAction(
|
||||
text: "Action 1",
|
||||
forcePlatform: selectedPlatform,
|
||||
onPressed: () {},
|
||||
),
|
||||
AdaptiveDialogAction(
|
||||
text: "Action 2",
|
||||
forcePlatform: selectedPlatform,
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
forcePlatform: selectedPlatform,
|
||||
);
|
||||
});
|
||||
},
|
||||
child: const Text("Show"),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Loading Indicator: "),
|
||||
AdaptiveIndicator(
|
||||
forcePlatform: selectedPlatform,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user