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 (pilot)
Apply a consistent structure to 5 example apps (simple_material_app, stateful_widget, dropdown_button, using_gradient, using_tabs): - lib/main.dart now contains only the app bootstrap: runApp + a const MyApp widget wrapping the app in a MaterialApp. - lib/example.dart holds the full screen (Scaffold, AppBar, and the focused code that demonstrates the example feature), marked with a '// Example:' banner comment. This makes it easy to pinpoint the code that teaches each concept while keeping the wrapping/chrome code uniform and minimal. Review this pilot before rolling the pattern out to the remaining apps.
This commit is contained in:
33
using_gradient/lib/example.dart
Normal file
33
using_gradient/lib/example.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'utils.dart' as utils;
|
||||
|
||||
// Example: the focused code for this app.
|
||||
// A Container whose background uses a custom LinearGradient.
|
||||
class Example extends StatelessWidget {
|
||||
const Example({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Using Gradient"),
|
||||
),
|
||||
body: Container(
|
||||
// Decoration
|
||||
decoration: BoxDecoration(
|
||||
// Add Gradient
|
||||
gradient: utils.getCustomGradient(),
|
||||
),
|
||||
// Center the content
|
||||
child: const Center(
|
||||
// Add Text
|
||||
child: Text(
|
||||
"Hello World!",
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './utils.dart' as utils;
|
||||
import 'example.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
// Title
|
||||
title: "Using Gradient",
|
||||
// Home
|
||||
home: Scaffold(
|
||||
// Appbar
|
||||
appBar: AppBar(
|
||||
// Title
|
||||
title: Text("Using Gradient"),
|
||||
),
|
||||
// Body
|
||||
body: Container(
|
||||
// Center the content
|
||||
decoration: BoxDecoration(
|
||||
// Add Gradient
|
||||
gradient: utils.getCustomGradient()),
|
||||
// Center the content
|
||||
child: Center(
|
||||
// Add Text
|
||||
child: Text(
|
||||
"Hello World!",
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
)))));
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: "Using Gradient",
|
||||
home: const Example(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user