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 (single-file apps)
Convert 20 more single-file apps to the validated pattern: lib/main.dart holds only the runApp + MaterialApp bootstrap, while a new lib/example.dart holds the full screen (Scaffold, AppBar) and the focused example code. Apps: enabling_splash_screen, getx_counter_app, image_from_network, infinite_list, load_local_image, load_local_json, persist_key_value, push_notifications, sliver_app_bar_example, stateless_widgets, tic_tac_toe, tip_calculator, using_alert_dialog, using_edittext, using_expansionpanel, using_http_get, using_interactiveviewer, using_snackbar, using_stepper, using_theme
This commit is contained in:
47
using_edittext/lib/example.dart
Normal file
47
using_edittext/lib/example.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Example: a TextField that appends submitted lines to a result view.
|
||||
class Example extends StatefulWidget {
|
||||
const Example({super.key});
|
||||
|
||||
@override
|
||||
State<Example> createState() => _ExampleState();
|
||||
}
|
||||
|
||||
class _ExampleState extends State<Example> {
|
||||
String results = "";
|
||||
|
||||
final TextEditingController controller = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Using EditText"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
decoration:
|
||||
const InputDecoration(hintText: "Enter text here..."),
|
||||
onSubmitted: (String str) {
|
||||
setState(() {
|
||||
results = "$results\n$str";
|
||||
controller.text = "";
|
||||
});
|
||||
},
|
||||
controller: controller,
|
||||
),
|
||||
Text(results)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'example.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(
|
||||
home: MyEditText(),
|
||||
));
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyEditText extends StatefulWidget {
|
||||
const MyEditText({super.key});
|
||||
|
||||
@override
|
||||
MyEditTextState createState() => MyEditTextState();
|
||||
}
|
||||
|
||||
class MyEditTextState extends State<MyEditText> {
|
||||
String results = "";
|
||||
|
||||
final TextEditingController controller = TextEditingController();
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Using EditText"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
decoration: InputDecoration(hintText: "Enter text here..."),
|
||||
onSubmitted: (String str) {
|
||||
setState(() {
|
||||
results = "$results\n$str";
|
||||
controller.text = "";
|
||||
});
|
||||
},
|
||||
controller: controller,
|
||||
),
|
||||
Text(results)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
return MaterialApp(
|
||||
title: "Using EditText",
|
||||
home: const Example(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user